question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 one ArrayList<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) and dialog.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.

https://user-images.githubusercontent.com/47919702/145464953-d7a66468-7453-418d-8217-8032df648f62.mp4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
H4zh4ncommented, Jan 22, 2022

@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 the findViewById (best to put a null check there incase it’s a first run). I thought the jcplayer.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 the findViewById again) after jcplayer.kill() in that situation.

your comment saying below helped me figure this out.

have you tried calling jcplayer.kill() when second activity is finished? I think if your player activity is finished, the player also has to be finished.

1reaction
jeancsanchezcommented, Jan 21, 2022

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 ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

problem in syncing and timing the slides with audio file inserted
In the Animation Pane, make sure your audio clip is in first position at the top of the pane. Click the down arrow...
Read more >
TV Audio Out of Sync: How to Fix in seconds
Use AV Sync Slider on a Fire TV · Open the Settings menu. · Go to Display and Sounds > Audio. · Choose...
Read more >
Fix Audio Sync Drift in Your Videos Using Adobe Premiere ...
Tutorial for fixing audio drift in videos when syncing audio recorded on an external recorder. E.g. If your audio goes out of sync...
Read more >
Solved: Audio is not Syncing with Slideshow Play - 8939952
I have audio files tied to each slide in my project. I have transitions of objects based on the timing of the audio....
Read more >
Use Timings to Sync PowerPoint Audio and Animations
This article describes how to synchronize your audio narrations with your PowerPoint animations and slide transitions by applying the "Use Timings" option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found