0
0

Hi!

I am writing a simple mp3 player which can play streaming songs ( using my own protocol, where simply i transfer files over tcp )

This is a part of the player code…

[code:3t5r1ovd]
char* fileName = "tmp.mp3";

FMOD_RESULT result;
FMOD::System *f_system;
FMOD::Sound *f_sound;
FMOD::Channel *f_channel;

result = FMOD::System_Create(&f_system); // Create the main system object.
ERRCHECK(result);

result = f_system->init(32, FMOD_INIT_NORMAL, 0); // Initialize FMOD.
ERRCHECK(result);

result = f_system->createStream(fileName, FMOD_HARDWARE | FMOD_CREATESTREAM, 0, &f_sound);
ERRCHECK(result);

result = f_system->playSound(FMOD_CHANNEL_FREE, f_sound, false, &f_channel);
ERRCHECK(result);

printf("Now playing %s\n", fileName );
while(1)
{
// user interaction...
}

return 0;

[/code:3t5r1ovd]

The song plays for about 5 seconds, and stops. ( There are no buffer underflows as i am testing it out on my local machine )

This how i am simulating the file transfer
[code:3t5r1ovd]
int rfd = open( "sweet child of mine.mp3", O_RDONLY );
int wfd = open( "tmp.mp3", O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRGRP | S_IROTH );

char buf[65536];

int err=1;
while( err )
{
err = read( rfd, buf, 65536 );
b = write( wfd, buf, err );
sleep(2);
}

close(rfd);
close(wfd);
[/code:3t5r1ovd]

Any idea whats wrong with the code or the approach?

  • You must to post comments
0
0

You need to call eventsystem/system->update every few ms.

  • You must to post comments
0
0

I made the following change in the main loop…

[code:284bg3t6]
while(1)
{
f_system->update();
// rest of the code... ( no code yet )
}
[/code:284bg3t6]

But even then the sound stops after a few seconds :(
I am pretty sure that there is nothing wrong with the read/writes to the
tmp.mp3 as any media player seems to play it just fine as it is being "streamed"

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.