Music playback in background on Android

  • Hi,

    I'm working on a music player and my current focus is to port it to Android. I have problem to play music if the player is in background. The current song remains playing but it won't start the next track.

    The playback is implemented by using a QMediaPlayer instance and connecting it's signal QMediaPlayer::stateChanged to find out that the current track has stopped.

    I believe the program is suspended in background and either the signal is not sent or the code which should react to the signal is not executed.

    Is there any solution to my problem? I was looking for some information and it seems I need to use a service for this and that won't be available until Qt5.7. But that is only a guess.

  • @vlada this post (from the author of the Qt port to Android) may help you as interim solution until Qt 5.7 is out. Good luck!

  • @Pablo-J-Rogina
    Thank you for pointing me at the article. I didn't study the code really deeply but I'm afraid it is exactly the opposite to what I need. The article is about running C++ code in Android UI thread. But what I need is to run my code in the background (even if the UI part is not displayed).

    I found this BogDan's comment. I tried to use the second suggestion and in AndroidManifest.xml changed the value to true. That partially does the trick.

    However there still remain some problems. My player sometimes crashes when in background. I should not update the UI. But how do I recognize that my app is in background?

    Another problem is that in that case Android can kill my player at any time. I'm not sure how it works inside. But according to my experience with Android, if an application has an icon is notification area, it won't be killed by the system. My player doesn't have such icon.

    Do you have any ideas how can I solve these 2 problems? I'm sure I will need some Java code in the future but I'm trying to avoid it as long as possible.

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.