4

I am trying to play a video on my TV using chromecasting framework provided. The approach i followed for playing a mp4 works fine. But now i have different source to play. I have a video file pointed by m3u8 file placed on my server. So, for playing m3u8 file on TV i am using the following MediaInfo object with variants for content-type mentioned here. The MediaObject i am returning is:`

return new MediaInfo.Builder(Uri.parse(path).toString())
            .setStreamType(MediaInfo.STREAM_TYPE_LIVE)
            .setContentType("videos/mp4") //need to know **what should be content-type here**
            .setMetadata(movieMetadata)
            .setStreamDuration(mSelectedMedia.getData().getDuration() * 1000)
            .build();

Please guide me for playing m3u8 file on my chromecast or TV. Thanks

2 Answers 2

4

First of all, I don't see what issue you are running into; always include that in your post so that you can get a better response. Based on the description you have provided, it seems like you are casting a playlist pointing at some files; if that is the case, you shouldn't set the stream type to live stream, instead use the buffered type (like what you would do for a simple mp4). Secondly, what receiver are you using? Your receiver should be capable of handling m3u8 playlist. If you use a Styled or the Default receiver (or use the Reference receiver from our GitHub repo, then you should be fine. Finally, make sure you are using https for the vide streams (for playlists it is required) and also that your server supports CORS headers.

10
  • Ali thanks for your valuable reply, can you please guide a bit more about Receiver. I not getting at point where i can play with my Receiver device. Not sure do i need to write separate app and then how can i debug it on my chromecast device?
    – Safeer
    Commented Dec 2, 2016 at 7:59
  • You might want to take a look at the developers.google.com/cast/docs/developers to get an idea about the overall architecture and learn what components are needed to build an app; you need a sender app (the Android app that you wrote) and a receiver app (in javascript) that runs on chromecast. Instead of writing your own receiver, you can use one that Google provides. Details can be found in the link I mentioned earlier.
    – Ali Naddaf
    Commented Dec 2, 2016 at 8:25
  • Naddaf I am ok with the default receiver app (i am not doing anything on chromecast device), so not intervening in that. So can you please tell how can i play video of this type in TV: "livestreamapis.com/v2/accounts/xxx/events/xxx/videos/…" where all xs are representing integers.
    – Safeer
    Commented Dec 2, 2016 at 10:38
  • If you are using the Default Receiver, there is nothing special that you need to do; you just provide a MediaInfo that has the url of your m3u8 file and the stream type is set to MediaInfo.STREAM_TYPE_BUFFERED. You need to make sure that your server has CORS headers and your url is https.
    – Ali Naddaf
    Commented Dec 4, 2016 at 1:07
  • Server is supporting CORS and url is https too, but still when i pass it for casting, then it starts loading then eventually no video plays. I have changed STREAM_TYPE to BUFFERED and content type is application/x-mpegURL. But still video is not playing. Please note my URL is ending by few other parameters rather just m3u8.
    – Safeer
    Commented Dec 4, 2016 at 6:20
1

As suggested by @naddaf problem was with CORS. So, i simply added my domains (gstatic.com and one more in my case) on server from where i am getting requests for my media. And it all started working perfectly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.