Author Topic: Sound breaks while Android app in "Background" state  (Read 343 times)

Avtem

  • Posts: 1
Hello, everyone!
I'm trying to use BASS in Qt Quick Android application.
  My setup: Qt 5.12 (Qt quick(qml)), Android-device: LG-e610 (800Mhz Single-Core ARM Cortex-A5, 512MB RAM, android ver.4.1.2)

Everything works as expected when my app on the "foreground".
When it goes to the "background" state playback really struggles. Occurs sound breaks and my application can eventually crash (e.g. when I try to use other apps).
My app is just a blank-screen app that starts playback on create. It uses 20 mb of RAM and 15-20% CPU.
My phone is pretty old and "weak", but any other player plays sound with no problem and uses up to 10% of CPU.
I tried to increase buffer length (BASS_CONFIG_DEV_BUFFER) to 500 msecs but it did not help. Should I create a new thread for playback or it's something else I did wrong?

Code: [Select]
    QGuiApplication app(argc, argv);
    HSTREAM stream;
    QString path("/storage/sdcard0/Music/9.mp3");

    stream = BASS_StreamCreateFile(false, path.toStdString().c_str(), 0, 0, 0);
    BASS_ChannelPlay(stream, false);


    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();

Ian @ un4seen

  • Administrator
  • Posts: 22959
You could try raising the BASS_CONFIG_DEV_PERIOD setting to 15 or 20, and see if that helps. But background apps do get lower priority on Android, and you may need to implement a "foreground service" to fix the problem. Here is some info on that:

   http://developer.android.com/guide/components/services.html#Foreground

Also, here is a modified version of the PLUGINS example that another user has provided:

   www.un4seen.com/stuff/android-service.zip