Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix MP3 player
  • Loading branch information
erorcun committed Feb 19, 2021
1 parent bf7280b commit 139c6bfcf3dd2e2f8e26d987b6da6db51645f210
Showing with 170 additions and 190 deletions.
  1. +87 −97 src/audio/sampman_miles.cpp
  2. +83 −93 src/audio/sampman_oal.cpp
@@ -2046,141 +2046,131 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream)
bool bool
cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream) cSampleManager::StartStreamedFile(uint8 nFile, uint32 nPos, uint8 nStream)
{ {
int i = 0;
uint32 position = nPos; uint32 position = nPos;
char filename[MAX_PATH]; char filename[MAX_PATH];


if ( m_bInitialised && nFile < TOTAL_STREAMED_SOUNDS ) if ( !m_bInitialised || nFile >= TOTAL_STREAMED_SOUNDS )
return false;

if ( mp3Stream[nStream] )
{ {
if ( mp3Stream[nStream] ) AIL_pause_stream(mp3Stream[nStream], 1);
{ AIL_close_stream(mp3Stream[nStream]);
AIL_pause_stream(mp3Stream[nStream], 1); }
AIL_close_stream(mp3Stream[nStream]); if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
} {

do
if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER )
{ {
uint32 i = 0; // Just switched to MP3 player
do { if ( !_bIsMp3Active && i == 0 )
if(i != 0 || _bIsMp3Active) { {
if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0; if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] )

position = 0;
_CurMP3Pos = 0; tMP3Entry *e = _pMP3List;

tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);

if(mp3) {
mp3 = _pMP3List;
if(mp3 == NULL) {
_bIsMp3Active = false;
nFile = 0;
strcpy(filename, m_szCDRomRootPath);
strcat(filename, StreamedNameTable[nFile]);

mp3Stream[nStream] =
AIL_open_stream(DIG, filename, 0);
if(mp3Stream[nStream]) {
AIL_set_stream_loop_count(
mp3Stream[nStream], 1);
AIL_set_stream_ms_position(
mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream],
0);
return true;
}


return false; // Try to continue from previous song, if already started
} if(!_GetMP3PosFromStreamPos(&position, &e) && !e) {
nFile = 0;
strcpy(filename, m_szCDRomRootPath);
strcat(filename, StreamedNameTable[nFile]);

mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
if ( mp3Stream[nStream] )
{
AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position(mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream], 0);
return true;
} }
return false;


if(mp3->pLinkPath != NULL) } else {
mp3Stream[nStream] = if ( e->pLinkPath != NULL )
AIL_open_stream(DIG, mp3->pLinkPath, 0); mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0);
else { else {
strcpy(filename, _mp3DirectoryPath); strcpy(filename, _mp3DirectoryPath);
strcat(filename, mp3->aFilename); strcat(filename, e->aFilename);


mp3Stream[nStream] = mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
AIL_open_stream(DIG, filename, 0);
} }

if(mp3Stream[nStream]) { if ( mp3Stream[nStream] ) {
AIL_set_stream_loop_count(mp3Stream[nStream], 1); AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position(mp3Stream[nStream], 0); AIL_set_stream_ms_position(mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream], 0); AIL_pause_stream(mp3Stream[nStream], 0);

_bIsMp3Active = true;

return true; return true;
} }

// fall through, start playing from another song
_bIsMp3Active = false;
continue;
} }
if ( nPos > nStreamLength[STREAMED_SOUND_RADIO_MP3_PLAYER] ) } else {
position = 0; if(++_CurMP3Index >= nNumMP3s) _CurMP3Index = 0;


tMP3Entry *e; _CurMP3Pos = 0;
if ( !_GetMP3PosFromStreamPos(&position, &e) )
tMP3Entry *mp3 = _GetMP3EntryByIndex(_CurMP3Index);
if ( !mp3 )
{ {
if ( e == NULL ) mp3 = _pMP3List;
if ( !_pMP3List )
{ {
nFile = 0; nFile = 0;
_bIsMp3Active = 0;
strcpy(filename, m_szCDRomRootPath); strcpy(filename, m_szCDRomRootPath);
strcat(filename, StreamedNameTable[nFile]); strcat(filename, StreamedNameTable[nFile]);
mp3Stream[nStream] =
AIL_open_stream(DIG, filename, 0); mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
if(mp3Stream[nStream]) { if ( mp3Stream[nStream] )
AIL_set_stream_loop_count( {
mp3Stream[nStream], 1); AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position( AIL_set_stream_ms_position(mp3Stream[nStream], position);
mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream], 0); AIL_pause_stream(mp3Stream[nStream], 0);
return true; return true;
} }

return false; return false;
} }
} }

if(mp3->pLinkPath != NULL)
if ( e->pLinkPath != NULL ) mp3Stream[nStream] = AIL_open_stream(DIG, mp3->pLinkPath, 0);
mp3Stream[nStream] = AIL_open_stream(DIG, e->pLinkPath, 0); else {
else
{
strcpy(filename, _mp3DirectoryPath); strcpy(filename, _mp3DirectoryPath);
strcat(filename, e->aFilename); strcat(filename, mp3->aFilename);


mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0); mp3Stream[nStream] =
AIL_open_stream(DIG, filename, 0);
} }


if ( mp3Stream[nStream] ) if(mp3Stream[nStream]) {
{
AIL_set_stream_loop_count(mp3Stream[nStream], 1); AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position(mp3Stream[nStream], position); AIL_set_stream_ms_position(mp3Stream[nStream], 0);
AIL_pause_stream(mp3Stream[nStream], 0); AIL_pause_stream(mp3Stream[nStream], 0);
#ifdef FIX_BUGS
_bIsMp3Active = true; _bIsMp3Active = true;
#endif
return true; return true;
} }

_bIsMp3Active = false;


} while(++i < nNumMP3s); }

_bIsMp3Active = 0;
position = 0;
nFile = 0;
}

strcpy(filename, m_szCDRomRootPath);
strcat(filename, StreamedNameTable[nFile]);

mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
if ( mp3Stream[nStream] )
{
AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position(mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream], 0);
return true;
} }
while ( ++i < nNumMP3s );
position = 0;
nFile = 0;
} }
strcpy(filename, m_szCDRomRootPath);
strcat(filename, StreamedNameTable[nFile]);


mp3Stream[nStream] = AIL_open_stream(DIG, filename, 0);
if ( mp3Stream[nStream] )
{
AIL_set_stream_loop_count(mp3Stream[nStream], 1);
AIL_set_stream_ms_position(mp3Stream[nStream], position);
AIL_pause_stream(mp3Stream[nStream], 0);
return true;
}
return false; return false;
} }


0 comments on commit 139c6bf

Please sign in to comment.