如何使用QMediaPlayer播放流媒体音频
How to play streaming audio with QMediaPlayer?
我有来自服务器的音频流,我想在程序中使用QMediaPlayer
播放。当我第一次将文件下载到QBuffer
,然后从播放器调用setMedia
和play
方法时,一切都正常。但如果我想在流仍在工作时播放音乐,媒体播放器只将声音播放到调用setMedia
方法时的位置,然后停止。有什么可能的方法让它像我想的那样工作吗?非常感谢。
如果您以正确的方式初始化播放器,我认为没有理由不工作。
由于你还没有分享你写的代码(如果我留下评论,我今天剩下的时间都看不到你的回复),我会在这里留下一些示例代码。看看下面的代码是否适合您。
QMediaPlayer* player = new QMediaPlayer(this, QMediaPlayer::StreamPlayback);
player->setMedia(QUrl("http://vpr.streamguys.net/vpr64.mp3"));
player->setVolume(80);
player->play();
如果是这样的话,可以通过更改流的url来尝试同样的操作。
编辑:我假设玩家在更新之前已经耗尽了缓冲区。试着关注bufferStatus
和QMediaPlayer::MediaStatus
。我引用文件:
bufferStatus : const int
This property holds the percentage of the temporary buffer filled before playback begins or resumes, from (empty) to (full).
When the player object is buffering; this property holds the percentage of the temporary buffer that is filled. The buffer will need to reach 100% filled before playback can start or resume, at which time mediaStatus() will return BufferedMedia or BufferingMedia. If the value is anything lower than 100, mediaStatus() will return StalledMedia.
通过音频输出:
QByteArray* yourSoundData = blah blah...;
QBuffer* buffer = new QBuffer;
buffer->setData(yourSoundData);
buffer->open(QBuffer::ReadOnly);
QAudioFormat format; // According to your sound format (e.g. wav)
format.setSampleRate(22050);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/wav");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format)) {
qWarning() << "Raw audio format not supported by backend, cannot play audio.";
return;
}
QAudioOutput* audio = new QAudioOutput(format, this);
audio->start(buffer);
更多信息:http://doc.qt.io/qt-5/qaudiooutput.html
- 当直接渲染到WASAPI时,两个流中的一个流没有音频输出
- DSP过滤用于流媒体
- C - 不带CIT或COUT的流媒体运算符
- 流媒体错误:在退出上一个呼叫之前,请再次调用InternetStatusCallback
- 当流媒体关闭流程时,应将boost :: async_read返回的bost :: async_read返回的error
- c++:流媒体和速率调节
- 如何使用live555流媒体转发
- visual如何在C++中将捕获的流媒体视频保存到avi文件中
- 使用Qt多媒体和小工具播放网络流媒体视频
- 设计一个C++的 asio 流媒体服务器
- 在.NET中从iPad/iPhone/iPod Touch到PC(AirTunes)的流媒体音乐
- 如何使用QMediaPlayer播放流媒体音频
- Qt音乐流媒体
- 松下相机流媒体MJPEG视频与G.726音频
- 来自Shotcast和Icecast服务器的流式音频文件
- C++/OpenCV流媒体摄像机视频/图像(MJPEG)从套接字进入浏览器(Windows 8.1)
- 如何使用QTcp-Server套接字创建HTTP MJPEG流媒体服务器
- 使用Python/ c++ /Java流媒体直播视频到网页的最佳方法
- 流媒体视频从DirectX到HTML5
- Live555问题,同时通过互联网流媒体