4

I have a .m3u8 URL(for track) and a .vtt URL(for track details). I am developing a radio in android where details of every track comes with .vtt file.

So my question is how can I synchronize both track url and .vtt url in MediaPlayer.

My radio is playing good but I am unable to get the details of track.

Q.What is need of using .vtt file?

Ans. Because the radio contains infinite songs and every song has its own details. thats why there is need to synchronize tracks and its details.

Here is my .vtt file structure.

WEBVTT

1
00:00:00.000 --> 00:03:22.176
NOW PLAYING: <b>Don&#39;t Go</b> - Jon Tarifa
NOTE https://play.unplug.de/images/artwork.php?id=113043444&w=400

2
00:03:22.176 --> 00:06:28.725
NOW PLAYING: <b>Treat You Better</b> - Shawn Mendes
NOTE https://play.unplug.de/images/artwork.php?id=112983776&w=400

3
00:06:28.725 --> 00:09:46.954
NOW PLAYING: <b>Used To Have It All</b> - Fais &amp; Afrojack
NOTE https://play.unplug.de/images/artwork.php?id=113044015&w=400

4
00:09:46.954 --> 00:13:45.330
NOW PLAYING: <b>Hurts</b> - Emeli Sandé
NOTE https://play.unplug.de/images/artwork.php?id=113029897&w=400
...
...

If anyone knows how to, please answer.

Thanks in Advance.

Community
  • 1
  • 1
Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40

3 Answers3

2

If the .vtt file will be consistent, I think you simply need to parse the vtt file for track no, start - end times, song, artist, and thumbnail url. Then you can implement sync between trak details and track quite easily.

koray1396
  • 118
  • 2
  • 6
  • Yes after getting failure from all solutions I just parse it manually. it parse successfully but still I am getting problem. I try to explain the problem by steps.....Step-1 : Create Handler and while MediaPlayer starts playing then start that Handler....Step-2 : get current position from Media Player and sending it to my class which parsed it before and according to current position it send me the title and artwork of that track. But problem raises in step 2 that is when radio starts the second track then media player returns me 0 as the current position then again my parser gives same title – Vishal Chhodwani Apr 26 '17 at 11:22
  • Not sure if I understood right, but 'MediaPlayer.getCurrentPosition()' returns the playback position, not the track number. So you should implement your own solution to keep track of the track number. A simple solution would be to create a custom class as a track list handler, which would keep the list of available tracks, and media player would request the next track from this class. – koray1396 Apr 27 '17 at 10:49
0

MediaPlayer does not have good support that. Consider ExoPlayer

Fung
  • 961
  • 1
  • 8
  • 17
  • I tried Exoplayer it says that it support, but I don't get any exmaple of subtitle with audio track (.m3u8 format). if you have then please send me. – Vishal Chhodwani Apr 20 '17 at 06:27
0

I agree that it is good to implement ExoPlayer. You can see supported formats here:

https://google.github.io/ExoPlayer/supported-formats.html

You can follow up developer guide. It is a bit confusing but actually easy to move on. Don't forget to look at demo application's source code:

https://github.com/google/ExoPlayer/blob/release-v2/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java

Mertcan Çüçen
  • 466
  • 3
  • 13
  • I didn't see any example that a track playing with external WebVTT url. In this sample it has HLS supported video that has subtitle but inside the Track URL(.m3u8) not external. can you please provide any example that plays a music with synchronization of WebVTT from URL. – Vishal Chhodwani Apr 25 '17 at 19:06