Casting m3u8 file from android app - android

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

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.

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.

Related

How to play drm protected content in exoplayer?

I implemented exoplayer to play hls and dash contents. But I am struggling to play the dash content with widevine protection. I looked into the example app for Exoplayer, but I did n't get proper idea to implement. Currently I have a dash url and server url. How to easily implement exoplayer to play this content?
The easiest way for you to test with your content and ensure the playback works is to modify the ExoPlayer sample.
Specifically, if you look at the file where the sample manifest and license servers URL's are defined, you can either add your own example or just replace the URL's in one of the samples with your own.
The sample data is in the file: media.exolist.json: https://github.com/google/ExoPlayer/blob/release-v2/demos/main/src/main/assets/media.exolist.json
Assuming your content is using Widevine DRM, you can add or modify one of the entries like this:
{
"name": "HD (cenc)",
"uri": "https://storage.googleapis.com/wvmedia/cenc/h264/tears/tears.mpd",
"drm_scheme": "widevine",
"drm_license_uri": "https://proxy.uat.widevine.com/proxy?provider=widevine_test"
},
There are instructions here: https://github.com/google/ExoPlayer/blob/aeb306a164911aa1491b46c2db4da0d329c83c65/docs/demo-application.md#playing-your-own-content

Chromecast media Host State errors

I am trying to reproduce MPEG DASH, HLS and HSS(HTTP SmoothStreaming) streams by using modified sample applications provided by Google, but for now, only DASH is working.
I use:
https://github.com/googlecast/cast-custom-receiver
and
https://github.com/googlecast/CastVideos-android
As i see here https://developers.google.com/cast/docs/player?hl=en all protocols (HSS, HLS, DASH) should work without problems.
When i try to stream HSS and HLS i get this in Sample Media Receiver HUD:
Media Element State: "Error" (or "Abort")
.
.
.
Host State: "Fatal Error: code = 1"
Does anyone know what that error represents?
Also, sometimes i get this "Fatal Error: code = 0".
//UPDATE
I get this error when i try to cast HSS:
[2648.568s] [cast.receiver.MediaManager] Load metadata error cast_receiver.js:19
and the link is :
http://video3.smoothhd.com/ondemand/Turner_Sports_PGA.ism/Manifest
//UPDATE
HLS is working now. Problem is solved by setting CORS headers.
I don't know what HSS is and we don't mention HSS as a supported protocol either, nor we claim we support "all" protocols. We have listed the supported protocols/variations in the link that you have mentioned.
Problem was with codecs... I used streams encoded with VP1 video and WMAP audio codecs, so there were many errors. That is the reason for getting all those LOAD METADATA ERRORs.
And for CORS, you can use this: https://github.com/TOMODOcom/TOMODOkorz
Works like a charm :)

Possible to Override system .so library in App

I have to modify the Http Live Streaming implementation of Android Media Player.
The implementation is under the stagefright library
http://androidxref.com/4.0.4/xref/frameworks/base/media/libstagefright/httplive/LiveDataSource.cpp
I think these library will compile to a libstagefright.so which should be part of the Android system.
My question is if I make some changes to this library and compile a new libstagefright.so.
If I load this new libstagefright.so in my new application and call up the media player, will it use the code in my new libstagefright.so?
You will not be able to replace the original library, since when you try to loadLibrary it will load the library from within /system/lib. So unless you replace that (which is not possible on unrooted devices), you won't be able to load your custom code.
https://github.com/android/platform_system_core/blob/66ed50af6870210ce013a5588a688434a5d48ee9/rootdir/init.environ.rc.in sets the LD_LIBRARY_PATH by default. And loads it from these paths if available. If not, then your application's lib directory will be searched; but not the other way around.
I tried this with libwebkit.so in the past on various mainstream devices and haven't had any luck getting it to load instead of the one in /system/lib.
You can learn more by looking at:
doLoad from here https://android.googlesource.com/platform/libcore/+/41d00b744b7772f9302fdb94dddadb165b951220/luni/src/main/java/java/lang/Runtime.java
findLibrary here http://developer.android.com/reference/dalvik/system/BaseDexClassLoader.html#findLibrary(java.lang.String)
I'm pretty sure you can't replace the default class loader either for security reasons.
What you can do, though, is a straightforward fork the Media Player and have it load your modified libstagefright-modified.so. There could be other solutions, haven't looked at Media Player's code.
Knowing that all you want to do is parse the data before it gets to the MediaPlayer, I suggest not trying to alter the Android libraries. As soulseekah mentioned, it's not going to work without a rooted device. There are other options, although they both have drawbacks.
1) If you are only targeting recent versions (4.2 or later, I believe), you can take a look at new classes added to the android.media package, like MediaExtractor and MediaCodec. I'm not greatly familiar with those because they aren't available on the hardware with which I work, but they could be useful in getting to the raw data. Here is a decent sample of using them to play video. The drawback is those classes aren't available in earlier versions.
2) The other option is to put a local proxy on the device. Connect the MediaPlayer to the proxy and make the request to the media server yourself. See my answer here for a little more info on that. With a proxy, you will see all the data that comes through, giving you a chance to parse the ID3 tags. There is the drawback that you will have to parse the TS packets to put together an elementary stream (essentially doing the demuxer's job), but it will work with any version of Android. TS streams aren't difficult to disassemble, and ID3 tags aren't time consuming to parse, so I think this is a reasonable approach.

android MediaPlayer from url make it sound louder/amplify (not just volume up)

I play an mp3 file from url with android MediaPlayer class.
(everything works fine)
I want to amplify the sound, make it sound louder.
I don't mean just raise the device volume but to actually amplify the sound.
even in cost of loosing some quality.
(I want it to be done in code and not with 3rd party software) maybe with some kind of java library.
MediaPlayer doesn't have a out-of-the-box method for this. Doing what you try to do really goes in the direction of audio-manipulation. This means, that you should get the byte stream and modify it for your needs. E.g. read the MP3 specification and try to rise the amplitude.
A better approach would be to edit your current mp3 files with a professional desktop editing program and play the files just the usual way.
As per my understanding, this may not be directly allowed in MediaPlayer and you may need some mp3- manipulation algorithm or library to do this. I am looking into this, but you can use the following as a starting point:
Audio Effect
Looks like you're not supposed to directly use, that but one of its subclasses:
Equalizer
Virtualizer
BassBoost
PresetVerb
EnvironmentalReverb
Maybe it will help you, but I'm not exactly sure how to implement it. Will look into it.

Making Video files Android ready for playback over HTTP

I am working on an Android application which is supposed to play videos over HTTP on Android devices. Before we setup a server to host the video files just wanted a few things clarified:
As per the developer documentation, Android supports .mp4 and .3gp container formats for video. If we use H.263(video) - AAC LC (Audio) audio-video codec used for our media files will we be able to play the video by passing the URL to MediaPlayer class?
I did a little experiment and passed URL of one of the video files(.mp4) to the MediaPlayer class and got the following error:
Command PLAYER_INIT completed with an
error or info
PVMFErrContentInvalidForProgressivePlayback
From the docs, I came to know that for progressive playback, the video's index (e.g moov atom) should be at the start of the file.
Questions:
1. How do we make our videos Android-ready?
2. What are the different considerations that we need to make?
Please help.
Thanks.
You can actually achieve this using a pure Java implementation of ISO BMF ( MP4 ) container used JCodec ( http://jcodec.org ). For this use the following code:
MovieBox movie = MP4Util.createRefMovie(new File("bad.mp4"));
new Flattern().flattern(movie, new File("good.mp4"));
The side effect of 'Flattern' is creating a web optimized movie file that has it's header BEFORE the data.
You can also use similar functionality from command line:
java -cp jcodec-0.1.3-uberjar.jar org.jcodec.movtool.WebOptimize <movie>
The JCodec library can be downloaded from a project website.
I cross posted this question on Android-developers google group. Mark answered it there. Thanks Mark!
See this thread

Categories

Resources