Hi ,
I'm porting mplayer movie player as a plugin to android webkit browser.
I have ported mplayer to android platform.I'm able to download audio stream via android NP APIs and decompress mp3 data using mplayer.I have verified the decompressed data by playing it on x86 machine.
I'm trying the play the raw 16 bit (number of bits per sample ) PCM data via ANPAudioTrackInterfaceV0 APIs.
I have created audio track using
ANPAudioTrackInterfaceV0 as in external/webkit/WebKit/android/plugins/sample/main.cpp.
Playing via callback as mentioned in same above file.
I am getting crack sound with actual audio . The callback which expects the data is faster when compared to decoding and filling the buffer.
Please help me if any one encountered the same problem while playing audio with webkit plugin.
please use the following sample code for audio callback and creating the new track,
bool mplayer::FillSoundBuffer( char * data, int size )
{
if(!data)
return false;
if(size == 0)
return true;
memcpy(buff+(fcount++*size), data,size);
soundBufferSize = size;
return true;
}
bool mplayer::OpenDevice( int channels, int sampleSize, int sampleRate, int sndBufferSizeBytes)
{
SoundPlay* play = new SoundPlay;
play->file = NULL;
play->instance = pluginInstance;
play->track = gSoundI.newTrack(22050, kPCM16Bit_ANPSampleFormat, 2, audioCallback, play);
playTrack = play->track;
if (NULL == play->track) {
delete play;
return false;
}
else
{
if(play->track)
{
if (gSoundI.isStopped(play->track))
gSoundI.start(play->track);
}
}
return true;
}
static void audioCallback(ANPAudioEvent evt, void* user, ANPAudioBuffer* buffer)
{
switch(evt)
{
case kMoreData_ANPAudioEvent:
SoundPlay* play = reinterpret_cast<SoundPlay*>(user);
// if(play->track && soundBuffer!= NULL)
if(play->track)
{
memcpy(buffer->bufferData,soundBuffer,2048);
buffer->size = 2048;
gLogI.log(NULL,kDebug_ANPLogType," In audioCallback %d",buffer->size);
}
break;
}
}