Making video load faster in videoview - android

I play a video in a videoview from an URL...everything works fine and even the video plays
But the only problem is that the video takes almost 10 seconds to start playing which might be kind of annoying to the user
I have tried different URLs and its the same, the videos are 360p and 6sec long
Is it the default media player that is slow?
I have the stack overflow but could not find a suitable answer and ever searched for various 3 rd party videos libraries but could not find one
Even tried google's exoplayer library but the documentation is not that good in my view
Is there any solution how to overcome this problem?
my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String videeourl = "http://techslides.com/demos/sample-videos/small.3gp";
VideoView videoView = (FastVideoView)findViewById(R.id.video);
videoView.setMediaController(new MediaController(this));
videoView.setVideoPath(videeourl);
videoView.start();
}
}

Consider using Exoplayer. You can find the open source project here:
https://github.com/google/ExoPlayer
It uses Dynamic Adaptive Streaming over HTTP (DASH),breaks long content into HTTP segments.

You can follow this tutorial step-by-step to integrate ExoPlayer (ExoPlayer is the video player running in the Android YouTube app.) to your app, it's not that complicated as you thought.
https://codelabs.developers.google.com/codelabs/exoplayer-intro/index.html#0
By the way, there are a lot of good assignments in Google CodeLabs, you should check it out.

Related

YouTubePlayer not load Ad video with cueVideo()

I'm using YouTubePlayer to play YouTube video and use cueVideo(videoId) to load video, Which is working fine if video not contain Ad but video contain Ad then cueVideo(videoId) will not load video.
Also seen some discussion regards such problem which are suggested use loadVideo(videoId) instead of cueVideo(videoId) but as per my requirement i shown image until video not buffer and when video buffered hide image and show YouTubePlayer, So have to use cueVideo(videoId) instead of loadVideo(videoId).
Does any one having such issue ? thanks in advance for any suggestion or help.
Below is my code to load video :
youTubePlayer.cueVideo(videoId);
Preface: YouTube does not allow any View to be displayed over its video player.
My guess is that your "loading image", since it is displayed over the video player, is covering the ad that starts rolling for some videos. You can check this by reading the logs and keeping an eye for a warning thrown by the YouTube SDK.
I would suggest to use the YouTubePlayer.PlayerStateChangeListener callback, that offers the following methods:
abstract void onAdStarted()
abstract void onVideoStarted()
abstract void onLoaded(String videoId)
By using these methods, you can guarantee that your "loading image" is properly hidden just before the video or the ads starts playing.

Rooted Android streaming video client for local ip camera without any delays

I have an ip camera and I want to include the video stream in an Android activity. To do that I included a VideoLayout with id video and I added this code to the onCreate method in the Activity.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video);
Uri video = Uri.parse("rtsp://192.168.1.225/axis-media/media.amp");
videoView.setVideoURI(video);
videoView.start();
}
It works but there is an annoying delay of 10 seconds between the acquisition of the image from the camera and the displaying to the phone. I want the delay lesser than 2 seconds. I know the problem is related the fixed size of the buffer used for caching images during RTSP session. If I use vlc I can view the stream well by setting network-caching=0. Is there a way to do that in Android? The software destination is a ROOTED Android 4.0.3. Can I resolve by taking advantage of the root? I read that I can set the media.stagefright.cache-params of the build.prop file but I don't know if it is useful and how to set it..
Please help me! Thank you!

VideoView on Android, 2 issues

Trying to get a simple video clip playing in a loop. I got the video to play just fine. However, there are two problems I'm having.
If the user clicks the Home button, effectively hiding the app. Then they go back to it, the video is gone and doesn't reload.
Everything as far as initializing the video only takes place in the typical onCreate for the view that holds it. Where should I be calling the video from to start it to ensure that it always actually starts?
I can only get the device to find the video when pulling it from the web. I see in the logs that when I try to reference the clip from the RAW folder, it cannot find it.
VideoView myVideoView = (VideoView)findViewById(R.id.lighterView);
myVideoView.setVideoURI(Uri.parse("android.resource://com.android.AndroidVideoPlayer/"+R.raw.[videoclip]));
myVideoView.requestFocus();
myVideoView.start();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer myVideoView) {
myVideoView.setLooping(true);
}
});
The above chunk of code works fine if I use a URL to my website. But locally, it cannot find the clip.
Instead of just load/play video in onStart() method I suggest you to look at some well written code about VideoView, because the best way to connect your video to your interface is manage your VideoView(that implements surfaceView) callBack.
You can find a good example at the following link;)
http://alvinalexander.com/java/jwarehouse/android/core/java/android/widget/VideoView.java.shtml

is there a way to play streaming youtube video from my activity?

Somewhere in my Android app I would like to play a youtube video,
in my activity, in a small view.
I'm trying to do this using VideoView, but no luck so far..
I wrote a simple activity, here is my code so far:
public class MainView extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
/*working good but IT'S NOT youtube*/ //Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
/*NOT WORKING*/ //Uri video = Uri.parse("http://www.youtube.com/watch?v=hLQl3WQQoQ0&ob=av2e");
/*NOT WORKING (RTSP)*/ //Uri video = U-ri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&feature=grec_mobile&v=6WHRxXY67UA");
/*NOT WORKING (RTSP)*/Uri video = Uri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&v=wWub_aXPCVg");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
is it possible?
is there any other SDK component that can do that?
any ideas?
Thanks,
Amitos80
Google are releasing android components for YouTube "in the coming months", so hopefully by the end of 2012.
What I am doing in the meantime is using a WebView with loadData(), and passing in an IFrame as stated on the YoUTube API page. The Iframe is quite limited (most parameters don't even work, like controls=0), so if you need more flexibility like controlling the view then use the JavaScript API and then embed the JavaScript in the HTMl you pass into loadData.
I tried the Media Controller and couldn't get it to work, even though YouTube use it in there own app.
The other thing to try which i didn't get around to. Is to use the google search apis. You can specify a YouTube video and it will give you the URL's to the thumbnails, videos etc. This way you can get to the raw files (www.youtube.com/...../..../myfile.3gp) rather than calling a webpage. These might then be loadable in the MediaController.
If you know what video you want to view, you could just create an Intent with the url in it and use that to launch the Youtube app. You can see this SO Post for more details.
you can simply use youtube rtsp link in videoview as:
String myurl="rtsp://v4.cache4.c.youtube.com/CjYLENy73wIaLQk_ezfHQ9mvqRMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYN-__7O28NSPUAw=/0/0/0/video.3gp";
Uri video = Uri.parse(myurl);
mVideoView = new VideoView(this);
mVideoView.setVideoURI(video);
myMediaController = new MediaController(this);
it works simply for me.

Android : how to stream/play any music file on HTML page in android browser

There is one HTML page, streaming a music file and It's working on window but i need to run this html file on android.
also i need to control all the feature of music by javascript function e.g. play,pause,stop, volume up & down.
Can someone give me any idea?
Note : i am new to android but good hand in java. Just going through android tutorial and i came to know this feature can be done using webview. is it ?
Its not clear from the post if its a requirement that you have to play it on a html page or you just want to play the .mp3 file linked from some online page.
However, You can look at this Streaming Audio tutorial as an initial reference. The MediaPlayer API would be your goto place in android for anything to do with Audio/ Video. WebView is mainly for embedding a browser view within your android App.
Here is an example quite close to the thing you're going to do...
public class MyJSInterface{
private MediaPlayer mp = new MediaPlayer();
....
public void play(String url){
this.mp.setDataSource(url);
this.mp.prepare();
this.mp.start();
// AlterDialog etc.
}
public void stop(){
this.mp.stop();
}
....
}
HTML from your website:
function _play(url){
window.myappname.play(url);
}
function _stop(url){
window.myappname.stop();
}
thing you may need
Android Media

Categories

Resources