qt - 音频Qml失败

标签 qt audio qml

我正在尝试将背景音乐添加到小型应用程序中。我正在使用Window7和MinGW,但出现此错误:

ASSERT: "!url.isRelative() && (QQmlFile::urlToLocalFileOrQrc(url).isEmpty() || !QDir::isRelativePath(QQmlFile::urlToLocalFileOrQrc(url)))" in file qml\qqmltypeloader.cpp, line 1639 Invalid parameter passed to C runtime function. Invalid parameter passed to C runtime function.



这是代码:
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtMultimedia 5.8

Rectangle {
    id: main
    width: 600
    height: 400
    state: "mainMenu"
    property int margePixel: 30
    property int tailleInfoJeux: 200

    Image {
        id: background
        source:"qrc:/images/mainbkg"
        anchors.fill: parent
        fillMode: Image.PreserveAspectCrop
        sourceSize.height: 800
    }

    MediaPlayer{
        id: musicBkg
        source: "file:///Users/COMPUTER/Documents/candycrush/candy-crush-like-master/sound/bkg1.wav"
        autoLoad: true
        autoPlay: false
        volume: 1.0
        loops: Audio.Infinite

        Component.onCompleted: {
            //console.log(source==Qt.resolvedUrl("file:///Users/COMPUTER/Documents/candycrush/candy-crush-like-master/sound/Kalimba.mp3"))
            console.log(musicBkg.supportedAudioRoles())
        }
    }
}

这是.pro文件
# Add more folders to ship with the application, here
folder_01.source = qml/SweetCandy
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01

# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
    bonbon.cpp \
    niveau.cpp \
    case.cpp \
    controleur.cpp

# Installation path
# target.path =
QT += multimedia
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

OTHER_FILES += \
    qml/SweetCandy/main.qml \
    qml/SweetCandy/VueBonbon.qml \
    qml/SweetCandy/VueCase.qml

HEADERS += \
    bonbon.h \
    niveau.h \
    case.h \
    controleur.h

RESOURCES += \
    ressources.qrc

ICON = SweetCandyIconeLinux.png
macx: ICON = SweetCandyIconeMac.icns
win32: RC_FILE = SweetCandy.rc

最佳答案

试试这个,

source: "file:///c:\Users\COMPUTER\Documents\candycrush\candy-crush-like-master\sound\bkg1.wav"

关于qt - 音频Qml失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53333960/

相关文章:

qt - 在 ListView QML 中隐藏一个项目(委托(delegate))

c++ - 在 opengl 中渲染 obj 文件时出现黑色窗口

c++ - 在 Qt/C++ 中,有没有办法将按钮单击事件列表连接到一个插槽?

design-patterns - qml 文件夹列表模型

qt - Qt/QML 中的下拉刷新 ListView

qt - 如何在 Qt 中复制对象?

Android - 来自服务器的实时音频流

c++ - 现有 VoIP 系统的视频流 - 应该使用哪些库?

java - 在 Android 上查找音高

qt - 如何在 TableView rowDelegate 中右键单击时显示上下文菜单