QMediaPlayer won't move to next track on Android unless in focus
I have built a simple music-player and audio-book-player (two applications) using Qt. Originally developed for Nokia N9 converted to both Jolla and Android. Probably the two most used applications I have ever build for my self. On other words it has been working very well for many years.
The audio-book-player are mostly built using QML, including playing audio but with my own concept of play-lists. The music-player are using QML UI frontend with QMediaPlaylist and QMediaPlayer in C++.
Now converting to recent Qt (5.9.2) I run into same problem with them both;
I play a track/chapter and the phone locks the screen. The player will continue the current loaded track but will not move into the next track. It just take a nap without emitting any stateChanged(QMediaPlayer::State). When I unlock the phone it will nicely continue to the next track.
I figure that this is a problem in the QMediaPlayer as I am using my own play-list in the audio-book-player.
When I track the application state I found that when I lock the screen the application state goes from Qt::ApplicationActive to Qt::ApplicationSuspended, it never passes Qt::ApplicationHidde. I treat Active and Inactive the same and does not know if there is a split second of Inactive between.
What do do?
I'd like the player to nicely continue playing my book while I have my phone in the pocket. or especially while driving.
I have tested this on Andoid 4.2.2, 6.0.1 and 7.1.1
Interesting though is that the player now goes into pause when I receive a call, that has not always been the case.
Experienced that when I press the android "home" button the application will get two new states directly after each other;
First Qt::ApplicationInactive and then Qt::ApplicationSuspended
If I build the application using Qt 5.2.1 it works as expected and QMediaPlayer continues in the playlist while app in background.
I also tried Qt 5.6.3 where I had the same problem as in Qt 5.9.2.
While this solves my urgent problem (as I actually don't really care about the Qt version in this case) I do think there might be some kind of bug in here somewhere so I won't mark the thread solved just yet.
Did you check the bug report system to see if there's something related ?
I did search the tickets but found nothing that I could relate to this problem. If it is filed without "android" mentioned I would have missed it. But then again, this does not seem to be a problem if I compile for Desktop.
The backends are different between platforms so what you observe currently with Android is likely unique to Android.