Slider and duration not synced to audio playing
See original GitHub issue[Video attached at bottom for better explanation/visualization] A background on what I’m trying to achieve: I have an app that has two distinct activities, a main window and (obviously) the second one that has the player. The player is displayed in an AlertDialog, because I have two other different activities that require the same audio player. so to avoid writing same code three times I came up with the solution of having a custom AlertDialog that has your beautiful library and opens through a menu click in all three.
When I open the second activity, I can open the dialog, play the audio files (they are all mp3 files) with no issues. I have managed to make it if the dialog is dismissed while playing and called (opened) again, it is synced perfectly. I achieved this by simply making sure to not reload the player again (not fetching the view again) if it’s from the same Context as previous.
My Issue
When the dialog is dismissed while the audio is playing, and I return to main activity, and back to second, if I open the dialog, now the slider and the total/duration timer (AND play/pause button) is not synced, but current time of the audio is synced (the time the audio file is at). Slider is always at the end and total/duration time shows 00:00. I think mostly due to the fact that even if I open the same second activity I have to reload the player (do the findView …) because although I opened the same second activity, the Context changed, and I HAVE to reload stuff or else the dialog won’t show since I’m in a different context (still same activity but different context as previous one was destroyed).
I’m looking for way to refresh the slider and duration time of the audio file (AND the play/pause button accordingly) so it’s synced as well when I reopen the dialog when revisiting the activity again and the audio is still playing.
Some other stuff that might be irrelevant or maybe useful for you to identify the issue :
- I only create/have one
JcPlayerManagerListener
and oneArrayList<JcAudio>
and initialize them once. - I always run
initPlaylist()
on every dialog open again and do set the already created Manager and ArrayList to it everytime. - For now, I only run
... new Dialog(context, style)
anddialog.findViewById(R.id.audio_player)
when dialog is opened in a new context (meaning once every time user leaves and comes back). - Most of my variables are set as static.
I believe overall if I only have the main activity and the other three loaded as fragments I could fix the issue by opening the dialog in main always (or even have it as a view in main like the sample app), but I was hoping there was a way to fix the issue currently without going through a major change in my app since all three are tied to a ton of other stuff just to fix that small UI bug.
A demonstration of the issue : In some moments in the video you may see the timer/slider frozen, this is because I recorded a quick vid and when I edited it I slowed down the video so the on-vid text can be read, so no issues there. only the stuff not synced to player.
…
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@jeancsanchez Thank you so much for the great work. really appreciate it. everything works as intended now. do you still prefer patreon as a method to support you ? I want to makeup a bit for the hassle I put you through.
I had another issue so below is only a heads-up for those that comes across this thread with same design structure as me. hopefully it helps someone… If ever wanted to stop the player and swap the audios with new files when the dialog is opened (say opening same dialog from different activity that has different audios to be played), it’s best to place
jcplayer.kill()
before the thefindViewById
(best to put a null check there incase it’s a first run). I thought thejcplayer.kill()
only stops the player, but from what I looked at I believe it clears everything related to the player, so it’s maybe required to init (do thefindViewById
again) afterjcplayer.kill()
in that situation.your comment saying below helped me figure this out.
Fixed on version
2.7.1
.Just call
player.resume()
method before showing your dialog. I created a Pull Request for your repository with the changes needed.Thanks for feedaback ❤️