void _Music_Stop() { Music_Mute(true); Music_PauseVoice(false); SND_Pause(0); if (music_format == FORMAT_MP3) { //the thread freezes when paused and you can't kill it! Music_UnPause(); MP3Player_Stop(); } else if (music_format == FORMAT_MOD) { if (music_buf) { MODPlay_Stop(&mod); MODPlay_Unload(&mod); } } if (music_f) fclose (music_f); music_f = NULL; if (music_buf) free (music_buf); music_buf = NULL; if (musicArray) free (musicArray); musicArray = NULL; music_size = 0; was_playing = false; music_format = 0; }
///<summary> /// Handles shutdown ... ///</summary> WiiAudioMp3::~WiiAudioMp3() { if(myAudioBuffer != NULL) { MP3Player_Stop(); if(myAudioBuffer != NULL) { delete myAudioBuffer; //free(myAudioBuffer); myAudioBuffer = NULL; } //delete myAudioBuffer; } }
/* Plays a MP3 file */ void mp3_player(file_handle* allFiles, int numFiles, file_handle* curFile) { // Initialise the audio subsystem ASND_Init(); MP3Player_Init(); // Find all the .mp3 files in the set of allFiles, and also where our file is. int curMP3 = 0, i = 0; for(i = 0; i < numFiles; i++) { if(!strcmp(allFiles[i].name,curFile->name)) { curMP3 = i; break; } } int first = 1; for(i = curMP3; i < numFiles; i++) { int ret = PLAYER_NEXT; if(!first && useShuffle) { i = (rand() % numFiles); } // if it's .mp3 if((strlen(allFiles[i].name)>4) && endsWith(allFiles[i].name,".mp3")) { ret = play_mp3(&allFiles[i], numFiles, i); } if(ret == PLAYER_STOP) { break; } if(ret == PLAYER_PREV) { i-=2; } first = 0; } MP3Player_Stop(); }
int play_mp3(file_handle *file, int numFiles, int curMP3) { int ret = PLAYER_NEXT; file->offset = 0; MP3Player_PlayFile(file, &mp3Reader, NULL); uiDrawObj_t* player = NULL; while(MP3Player_IsPlaying() || ret == PLAYER_PAUSE ) { u32 buttons = PAD_ButtonsHeld(0); if(buttons & PAD_BUTTON_B) { // Stop while((PAD_ButtonsHeld(0) & PAD_BUTTON_B)){VIDEO_WaitVSync();}; MP3Player_Stop(); ret = PLAYER_STOP; } else if(buttons & PAD_BUTTON_START) { // Pause while((PAD_ButtonsHeld(0) & PAD_BUTTON_START)){VIDEO_WaitVSync();}; if(ret != PLAYER_PAUSE) { MP3Player_Stop(); ret = PLAYER_PAUSE; } else { MP3Player_PlayFile(file, &mp3Reader, NULL); // Unpause ret = PLAYER_NEXT; } } else if(buttons & PAD_BUTTON_X) { // VOL+ if(volume!=255) volume++; MP3Player_Volume(volume); } else if(buttons & PAD_BUTTON_Y) { // VOL- if(volume!=0) volume--; MP3Player_Volume(volume); } else if(buttons & PAD_TRIGGER_R) { // Next MP3Player_Stop(); ret = PLAYER_NEXT; } else if(buttons & PAD_TRIGGER_L) { // Previous MP3Player_Stop(); ret = PLAYER_PREV; } else if(buttons & PAD_BUTTON_RIGHT) { // Fwd MP3Player_Stop(); if(file->offset+0x8000 < file->size) { file->offset += 0x8000; MP3Player_PlayFile(file, &mp3Reader, NULL); } else { ret = PLAYER_NEXT; break; } } else if(buttons & PAD_BUTTON_LEFT) { // Rewind MP3Player_Stop(); if(file->offset-0x10000 > 0) file->offset -= 0x10000; else file->offset = 0; MP3Player_PlayFile(file, &mp3Reader, NULL); } else if(buttons & PAD_TRIGGER_Z) { // Toggle Shuffle while((PAD_ButtonsHeld(0) & PAD_TRIGGER_Z)){VIDEO_WaitVSync();}; useShuffle ^=1; } uiDrawObj_t* display = updatescreen_mp3(file, ret, numFiles, curMP3); if(player != NULL) { DrawDispose(player); } DrawPublish(display); player = display; usleep(5000); } if(player != NULL) DrawDispose(player); return ret; }
///<summary> /// Stops playing the audio and resets all counters. ///</summary> void WiiAudioMp3::stop() { ASSERT(myAudioBuffer != NULL); MP3Player_Stop(); }