aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Reisenauer <kd7tck@msn.com>2016-05-11 20:15:37 -0700
committerJoshua Reisenauer <kd7tck@msn.com>2016-05-11 20:15:37 -0700
commit9737c58054d5d0cc636fca0c998b31a69d501970 (patch)
treedf4dc65349c893ac125ae7e5fca8cf4e60bed57c /src
parent529d20ee6a29528a0da456be4f08eb7caa56df21 (diff)
downloadraylib-9737c58054d5d0cc636fca0c998b31a69d501970.tar.gz
raylib-9737c58054d5d0cc636fca0c998b31a69d501970.zip
PlayMusicStream now uses index
Diffstat (limited to 'src')
-rw-r--r--src/audio.c29
-rw-r--r--src/audio.h2
-rw-r--r--src/raylib.h2
3 files changed, 21 insertions, 12 deletions
diff --git a/src/audio.c b/src/audio.c
index f89be8bf..6a8d251e 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -763,19 +763,18 @@ void SetSoundPitch(Sound sound, float pitch)
//----------------------------------------------------------------------------------
// Start music playing (open stream)
-void PlayMusicStream(char *fileName)
+// returns 0 on success
+int PlayMusicStream(int musicIndex, char *fileName)
{
- int musicIndex;
+ int musicIndex = index;
int mixIndex;
- for(musicIndex = 0; musicIndex < MAX_MUSIC_STREAMS; musicIndex++) // find empty music slot
- {
- if(currentMusic[musicIndex].stream == NULL && !currentMusic[musicIndex].chipTune) break;
- else if(musicIndex = MAX_MUSIC_STREAMS - 1) return;
- }
+
+ if(currentMusic[musicIndex].stream != NULL || currentMusic[musicIndex].chipTune) return 1; // error
+
for(mixIndex = 0; mixIndex < MAX_AUDIO_CONTEXTS; mixIndex++) // find empty mix channel slot
{
if(mixChannelsActive_g[mixIndex] == NULL) break;
- else if(musicIndex = MAX_AUDIO_CONTEXTS - 1) return;
+ else if(musicIndex = MAX_AUDIO_CONTEXTS - 1) return 2; // error
}
@@ -787,6 +786,7 @@ void PlayMusicStream(char *fileName)
if (currentMusic[musicIndex].stream == NULL)
{
TraceLog(WARNING, "[%s] OGG audio file could not be opened", fileName);
+ return 3; // error
}
else
{
@@ -828,9 +828,18 @@ void PlayMusicStream(char *fileName)
currentMusic[musicIndex].ctx = InitAudioContext(48000, mixIndex, 2, true);
}
- else TraceLog(WARNING, "[%s] XM file could not be opened", fileName);
+ else
+ {
+ TraceLog(WARNING, "[%s] XM file could not be opened", fileName);
+ return 4; // error
+ }
+ }
+ else
+ {
+ TraceLog(WARNING, "[%s] Music extension not recognized, it can't be loaded", fileName);
+ return 5; // error
}
- else TraceLog(WARNING, "[%s] Music extension not recognized, it can't be loaded", fileName);
+ return 0; // normal return
}
// Stop music playing for individual music index of currentMusic array (close stream)
diff --git a/src/audio.h b/src/audio.h
index fef85b4f..d09c4acc 100644
--- a/src/audio.h
+++ b/src/audio.h
@@ -100,7 +100,7 @@ bool IsSoundPlaying(Sound sound); // Check if a so
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
-void PlayMusicStream(char *fileName); // Start music playing (open stream)
+int PlayMusicStream(int musicIndex, char *fileName); // Start music playing (open stream)
void UpdateMusicStream(void); // Updates buffers for music streaming
void StopMusicStream(int index); // Stop music playing (close stream)
void PauseMusicStream(int index); // Pause music playing
diff --git a/src/raylib.h b/src/raylib.h
index a6507906..cb17aa78 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -894,7 +894,7 @@ bool IsSoundPlaying(Sound sound); // Check if a so
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
-void PlayMusicStream(char *fileName); // Start music playing (open stream)
+int PlayMusicStream(int musicIndex, char *fileName); // Start music playing (open stream)
void UpdateMusicStream(void); // Updates buffers for music streaming
void StopMusicStream(int index); // Stop music playing (close stream)
void PauseMusicStream(int index); // Pause music playing