Phonon::MediaSource from QBuffer
-
Hello, I'm new to Phonon and came across the following problem.
I need to play mp3 file. If I use Phonon::MediaSource( "./mediafile.mp3" ) and pass it to Phonon::MediaObject, then everything works ok. But the problem is that I have serialized contents of mediafile in the form of QByteArray. I am trying to play it the following way:
@
Phonon::AudioOutput audioOutput( Phonon::MusicCategory, NULL );
Phonon::MediaObject mediaObject( NULL );
Phonon::createPath( &mediaObject, &audioOutput );QFile file( "./about_hackers.mp3" );
file.open( QIODevice::ReadOnly );QByteArray ss( file.readAll( ) );
QBuffer buff( &ss, NULL );
buff.open( QIODevice::ReadOnly );Phonon::MediaSource source( &buff );
QObject::connect( &mediaObject, SIGNAL(finished()), &app, SLOT(quit()) );
mediaObject.setCurrentSource( source );
mediaObject.play( );return app.exec();
@However while using this code, I get the following error:
@xine is asking to seek behind the end of the data stream@Can someone help me solve this problem? or just give a better idea how to play serialized audio (different formats possible).
-
Okay... from documentation:
bq. MediaSource::MediaSource ( QIODevice * ioDevice )
Creates a MediaSource object for the QIODevice specified by ioDevice.
This constructor can be very handy in the combination of QByteArray and QBuffer.
If you need to fetch multimedia data from a source that is not supported by MediaSource, you should subclass QIODevice and use this MediaSource constructor. It is important that you reimplement QIODevice::isSequential(), as it is used by MediaSource to determine if the media source is seekable.So, guessing you're missing the isSequential()?
Also, by default Phonon uses the GStreamer backend on linux, so you could get support for other formats by just installing the appropriate GStreamer plugin..
-
[quote author="jim_kaiser" date="1308302390"]Okay... from documentation:
So, guessing you're missing the isSequential()?
[/quote]I'm try to use QFile as MediaSource to access to mp3 files in Qt Resource (qrc). And I have the same problem as MiGryz.
Reimplement isSequential() in QFile with a 'false' result have no effect.
Mp3 sometimes playing, sometimes not, sometimes breaks in the middle.If I open the same mp3 as local files(not from qrc) - no problem.