QMediaPlayer 在 qt5 中不起作用
Posted
技术标签:
【中文标题】QMediaPlayer 在 qt5 中不起作用【英文标题】:QMediaPlayer doesn't work in qt5 【发布时间】:2013-10-07 17:20:03 【问题描述】:我在 Mac OS X 10.8 和 Qt 5.1 上使用 Xcode 4.6。我想在我的应用程序中使用 QMeduaPlayer 类。这是我的代码:
#include <QApplication>
#include <QMediaPlayer>
int main(int argc, char *argv[])
QApplication a(argc, argv);
QMediaPlayer* pl = new QMediaPlayer();
pl->setMedia(QUrl::fromLocalFile("Crashday.wav"));
pl->play();
a.exec();
但它不起作用,我在控制台中看到:
objc97058: Class AVFCaptureFramesDelegate is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class AVFMediaRecorderDelegate is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class AVFCameraSessionObserver is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfcamera_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class AVFMediaPlayerSessionObserver is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfmediaplayer.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqavfmediaplayer_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class TransparentQTMovieView is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class HiddenQTMovieView is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine_debug.dylib. One of the two will be used. Which one is undefined.
objc97058: Class QTMovieObserver is implemented in both /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine.dylib and /Users/liri/Qt/5.1.1/clang_64/plugins/mediaservice/libqqt7engine_debug.dylib. One of the two will be used. Which one is undefined.
【问题讨论】:
【参考方案1】:试试
QMediaContent media(QUrl::fromLocalFile("Crashday.wav"));
pl->setMedia(media);
pl->play();
确保 wav 文件与已编译的可执行文件位于同一目录中。将插槽连接到mediaStatusChanged signal 并在QMediaPlayer::MediaStatus 等于 QMediaPlayer::LoadedMedia 时从那里开始播放可能会更好。
【讨论】:
以上是关于QMediaPlayer 在 qt5 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章
Qt5.natvis 在 VS 2015 更新 2 中不起作用
使用 NavigationToolbar 进行缩放在使用 pyqt 的 matplotlib 中不起作用