void _Music_Start() { int ret; // always init SND, so banner sounds play if music disabled ASND_Init(); ASND_Pause(0); if (CFG.music == 0) { dbg_printf(gt("Music: Disabled")); dbg_printf("\n"); return; } else { dbg_printf(gt("Music: Enabled")); dbg_printf("\n"); } was_playing = false; //get a music file ret = get_music_file(); if (ret==0) return; if (music_format == FORMAT_MP3) { MP3Player_Init(); MP3Player_Volume(0x80); // of 255 //ret = MP3Player_PlayBuffer(music_buf, music_size, NULL); ret = MP3Player_PlayFile(music_f, mp3_reader, NULL); dbg_printf("mp3 play: %s (%d)\n", ret? gt("ERROR"):gt("OK"), ret); if (ret) goto err_play; usleep(10000); // wait 10ms and verify if playing if (!MP3Player_IsPlaying()) { err_play: printf(gt("Error playing %s"), music_fname); printf("\n"); Music_Stop(); sleep(1); } } else { music_buf = malloc(music_size); if (!music_buf) { printf(gt("music file too big (%d) %s"), music_size, music_fname); printf("\n"); sleep(1); music_format = 0; return; } //printf("Loading...\n"); ret = fread(music_buf, music_size, 1, music_f); //printf("size: %d %d\n", music_size, ret); sleep(2); fclose(music_f); music_f = NULL; if (ret != 1) { printf(gt("error reading: %s (%d)"), music_fname, music_size); printf("\n"); sleep(2); free(music_buf); music_buf = NULL; music_size = 0; music_format = 0; return; } MODPlay_Init(&mod); ret = MODPlay_SetMOD(&mod, music_buf); dbg_printf("mod play: %s (%d)\n", ret?gt("ERROR"):gt("OK"), ret); if (ret < 0 ) { Music_Stop(); } else { MODPlay_SetVolume(&mod, 32,32); // fix the volume to 32 (max 64) MODPlay_Start(&mod); // Play the MOD } } }
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; }