Custom Mediaplayer Video Android quality option like Youtube - android

I am creating a Video Player Application with custom User interface using MediaPlayer with Surfaceview , the video is playing through url everything is working fine , now i want to add video quality option like 540p , 720p etc I have url of different quality to play same video but with different resolution but i dont know how i can change Datasource of playing video to set url of desired resolution at runtime and change it and play it from where it is resumed just like Youtube.. I tried following code
mp.setDataSource(String.valueOf(Uri.parse(params[0])));
mp.prepare();
mp.start();
by using this video is playing but when i try to change Datsourec again by passing new url to
mp.setDataSource(String.valueOf(Uri.parse(params[0])));
It gives me IllegalstateException.. i tried to release and reset Medaiplayer but not able to do it .. Any Help would be beneficial.

Related

Android VideoView set video quality in live streaming

I can load a video from the web. All works fine.
However, when a network connection is slow the video is buffering. So I want to set the quality of video while, streaming it automatically or manually.
I am blank about this.
If I am not mistaken, VideoView only plays the video. Here is the documentation on it, doesn't seem to have that option at all.
I'd suggest you use the youtube API instead if you can.

Android ExoPlayer changing selected track

I am using Andorid ExoPlayer to stream content from internet through http(HLS). When I start the player it is working ok, but when I try to change the quality of the playing content -
player.setSelectedTrack(TYPE_VIDEO, 1)
for example, I get and HTTP 403 Forbidden error. If I initialize the player and run again the content, it is fine. I am using the Demo project as a source.
Do you know what might be causing this behavior and what is the difference in playing the initial stream and changing the track?
Is there a way to reset the streaming without re-initializing the whole player, because the url is passed to the builder when the player is initializing?
I found the problem. The URL i was passing to the ExoPlayer was returned from an external API and was rather long so I haven't noticed that it is actually 2 URLs concatenated by "|"(http://my_url_1.m3u8|http://my_url_2.m3u8). The strange thing is that if you pass this string to the ExoPlayer it is playing a stream without error.. but if you try to change the quality of the playing stream you have problems.
You do not change quality of the stream using setSelectedTrack(). That is used for selecting what to play from the available streams (like what language of audio, subtitle, or for videos it is quite rare, but for example you can set up different camera angles of a sport event).
All of these streams can have multiple quality levels, and ExoPlayer's FormatEvaluator selects what quality to download based on the network conditions.
If the decoder is different when you select a new track, then the player needs to be reinitialized for continuing playback.
I suggest downloading the HLS manifest (.m3u8) manually, and then check the listed information, try the urls one by one in a browser. All should work, you should not get 403 test in this test either.

Video is not displayed in videoview in android?

My application uses a simple VideoView .It uses an 3gp file from assetsbut all i can see is a blank screen and music of that video.
Would someone help me to display the video?
P.S-I am trying it on emulator?
Do not use emulator for testing video playback. Its ability to handle video playback is very limited. You should use actual device to play videos.
Check https://stackoverflow.com/a/3005928/1341006 by Commonsware for more details

How to check Video is working or not in android?

I have one list and in this list I set the list of videos,
some video playing and some is not working. So I want to have a message(like video is not working) when video is not working or not playing.
How I check video is working or not ?
And I play this video URL in videoview.
If video is not working there are two reasons.
First the video's size is bigger then device and second, video is properly not working.

Pre-Load or Pre-Buffer .mp4 video in android app development

I am building an app that is successfully displaying an MP4 video file onButtonClick. I want to pre-buffer or preload the video's URI (remote url) so that it doesn't delay the playing of the video once the button is clicked. I want it to click and play right away, so pre-loading or buffering on the app launch splash screen seems like a fitting solution. Only thing is I don't know how. I have tons of Android Books, but hardly any of them cover buffering at all or they only cover audio.
Can anyone let me know how to buffer the video on a previous activity?
Thanks.
Google released ExoPlayer which provides a higher level for media playing : http://developer.android.com/guide/topics/media/exoplayer.html
It supports different state such as buffering in background :
// 1. Instantiate the player.
player = ExoPlayer.Factory.newInstance(RENDERER_COUNT);
// 2. Construct renderers.
MediaCodecVideoTrackRenderer videoRenderer = …
MediaCodecAudioTrackRenderer audioRenderer = ...
// 3. Inject the renderers through prepare.
player.prepare(videoRenderer, audioRenderer);
I used it in my own project and it seems pretty efficient. Also Google made a Full Demo of the player : https://github.com/google/ExoPlayer/tree/master/demo/src/main/java/com/google/android/exoplayer/demo/full which is more powerfull than simple demo.
You can use the MediaPlayer for preparing the video, like this:
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnPreparedListener(<implementation of MediaPlayer.OnPreparedListener>);
mediaPlayer.setDataSource(dataSource);
mediaPlayer.prepareAsync();
After the call prepareAsync() the mediaplayer will buffer your video.
The MediaPlayer.OnPreparedListener.onPrepared() will tell you if the mediaplayer is ready to play yet.
Just check the prepared flag and call mediaplayer.start() when you click your button "onButtonClick"
The native Android Browser doesn't buffer the media files (audio or video), so there is no way to do it on HTML5. As #bradenV2 said, you could copy the file to memory (you could use Phonegap if it is an App).

Categories

Resources