问题
i'm currently porting an application from Qt4(.8.4) to Qt5(.2.0). I'm nearly done with all the known changes like deprecated toAscii()-function, missing QtGui and so on. Now we had a music player using the phonon framework which is not supported any more and got replaced by the QtMultimedia module including the QMediaPlayer and a bunch of Audio-Handling classes.
Our implementation of the player takes a custom QIODevice. This device provides an interface to encrypted audiofiles on the disk. Now the player asks the device for x bytes, the device reads from the encrypted file, decrypts the bytes the player asked for and returns them.
Now I searched for a function in the multimedia-module to reuse my IODevice and found the following function:
void setMedia(const QMediaContent & media, QIODevice * stream = 0)
and used it as follows:
m_pDecryptingMediaDevice = new BYIODevice(filename);
m_pDecryptingMediaDevice->open(QIODevice::ReadOnly);
m_pPlayer->setMedia(0, m_pDecryptingMediaDevice);
where m_pDecryptingMediaDevice is the QIODevice-subclass and m_pPlayer the QMediaPlayer.
Now on Windows everything works as expected. The QMediaplayer changes its MediaStatus to QMediaPlayer::LoadingMedia and asks my device for bytes. Then changes to the QMediaPlayer::State PlayingState and the status is set to BufferedMedia. Everythings fine. Unfortunalety on Mac OS (10.9.1) I only get QMediaPlayer::PlayingState and nothing more. The player/audiobackend never asks my device for bytes and doesn't call any other function. I don't think that the mistake is concerned to the custom QIODevice but in the way it is given to the QMediaPlayer because the player doesn't even ask for any bytes or calls any function on the device.
I just tried to break it down to a little testproject:
QMediaPlayer *player = new QMediaPlayer(this);
QFile *music = new QFile("C:/Users/.../Music/Test.mp3");
music->open(QIODevice::ReadOnly);
player->setMedia(0, music);
connect(ui->pushButton, SIGNAL(clicked()), player, SLOT(play()));
connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(stateChanged(QMediaPlayer::State)));
Curiously this does not play at all - not on windows, not on Mac OS. What always works is giving an URL to the player like
Has someone any experience in a similar case according to streaming out of an QIODevice to QMediaPlayer using the function setMedia(const QMediaContent & media, QIODevice * stream = 0)? I am stuck with this.
Best regards and many thanks in advance.
Jan
回答1:
Just came to this page. There the available/chosen audio-backends for each platform are listed:
As you can see the DirectShow-Plugin (Windows) does support stream sources whereas AVM Foundation/Quicktime 7 (OSX) don't have streaming support. So I guess the only solution seems to ship a custom backend with the application (gstreamer, vlc).
回答2:
Anyway,try give empty QMediaContent() to setMedia instead of 0. It is working OK for me (but,I try it in linux) In your small test project,you use mp3 -- I'm not sure if it's supported.
来源:https://stackoverflow.com/questions/21404500/qmediaplayer-streaming-from-a-custom-qiodevice-with-encryption-on-mac-os-10-9