Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMediaPlayer doesn't work on Android 10



  • Hi,
    I created simple qt quick project to test QMediaPlayer.
    For some reason it works perfectly on Windows but it is silent on Android.
    I just changed main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    #include <QMediaPlayer>
    #include <thread>
    #include <QDebug>
    #include <QtConcurrent>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl)
        {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        },
        Qt::QueuedConnection);
        engine.load(url);
    
    
        // Test
        QMediaPlayer* player;
        auto thread = QtConcurrent::run([&player]()
        {
            using namespace std::chrono_literals;
            qDebug() << "Hello waiter";
            std::this_thread::sleep_for(3s);
    
            // ...
            player = new QMediaPlayer();
            player->setMedia(QUrl("http://www.hochmuth.com/mp3/Vivaldi_Sonata_eminor_.mp3"));
            player->setVolume(50);
            player->play();
    
            qDebug() << "Player is playing now";
    
        });
    
        return app.exec();
    }
    
    

    and added multimedia to .pro file.

    Logs:

    D libGui_armeabi-v7a.so: Hello waiter
    V MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@6d73455): Cookies: null
    D libGui_armeabi-v7a.so: Player is playing now
    V MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@a515e6a
    V MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService@6d73455): cookieHandler: java.net.CookieManager@a515e6a Cookies: null
    D NetworkSecurityConfig: No Network Security Config specified, using platform default
    

    Android: 10
    Qt: 5.15.1

    What's wrong with this code?


Log in to reply