Preload video on Android - android

I'm building an interactive movie of some sort , having more video clips that need to load between interactive scenes. The problem is there is a slight delay when starting the video which I believe it could be fixed by preloading the clip right before the previous one finishes. I've tried to start() the video and then stop() it, also seekTo() but i'm no getting the desired result.
Also I need to mention I'm using several VideoViews in the same Activity so I display the appropriate one.
The video files are loaded from the raw folder using the following code
videoView1 = new VideoView(this);
mediaController1= new MediaController(this);
mediaController1.setMediaPlayer(videoView1);
mediaController1.setVisibility(View.INVISIBLE);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sa1);
videoView1.setMediaController(mediaController1);
videoView1.setVideoURI(uri);
videoView1.requestFocus();
videoView1.start();
Thank you.

You can handle the loading in another thread with using, for example, AsyncTask while the user watches the pervious video.
http://developer.android.com/reference/android/os/AsyncTask.html

Related

In-Project-Videos - Where to store them and which format?

I have a quite complex android app and for several functions
i want to provide some tutorial videos inside the application.
Where do i have to put my Video-Files in my project? Also in the
drawable folder like my images?
Which format? (mpg, av, ...)
Do i also have to provide different qualities like mdpi, hdpi, ...?
I want to provide a ListView with a thumbnail of the video, a title and
a small description. after the user clicks on an item of the listview
i want the selected video to be played.
If you will have lots of videos, you probably don't want to put it inside apk, because apk size is limited + not every user wants to download and store on device app which is more than 50 mb. I recommend you to upload your videos to youtube ( just create you channel and upload as more videos as you need). Than you will be able to use youtube android api to show your videos inside app.
If you don't have lots of videos (overall < 50 mb), I recommend you to create folder row inside res folder and store all your videos there. Then you will be able to access it with built in VideoView. It supports next formats: Supported Media Formats. Example of usage VideoView:
VideoView videoView = (VideoView) findViewById(R.id.video_view);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.filename));
videoView.start();
Add a folder 'raw' to your res folder and store videos in them .
And for formats see : http://developer.android.com/guide/appendix/media-formats.html
And see this : https://stackoverflow.com/a/11348850/4465685

How to play .mp4 video on videoview

just want to know how to play a .mp4 video on videoview.
I got a tutorial from http://mrbool.com/how-to-play-video-formats-in-android-using-videoview/28299 and my app is not working.
I followed everything. i named my video "video.mp4".
I used this code to find the path of a specific video:
video_player_view.setVideoPath(Environment.getDataDirectory().getAbsolutePath() + "video.mp4");
I even made a "raw" folder and placed the video there. I used #raw/video.mp4 for it.
Can you guys help me out please. Thanks a lot.
Try assigning the video to the videoview with setVideoURI().
vidVwYourView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.your_video));
Just make sure 'your_video.mp4' is stored in your res/raw/ folder.
I have the similar problem. In may case, I remove video file extension and it works. So try with "video" instead of "video.mp4"

How can I play videos consecutively using VideoView control?

I have a video playing using the VideoView control,
VideoView vid;
vid = (VideoView)findViewById(R.id.video);
String urlpath = "android.resource://" + getPackageName() + "/" + R.raw.videoviewdemo;
vid.setVideoURI(Uri.parse(urlpath));
vid.start();
which works fine, but I assumed incorrectly that calling setVideoURI() and start() would wait for the first video to finish before playing the second. Is there any way to make the entire video play before moving on to the next line of code? Thanks
(I just started Android/Java programming a few days ago, and haven't written software in ANY language for years, so forgive me if I'm a little slow)
you can always use the completion listener to play the next video.
it will trigger as soon as current video gets finished.
keep track of the currently running video in the global integer.
update it to keep the track of them and get the next video to play
check this link
Listener (or handler) for video finish

Loading a video (mp4) file in android

VideoView v = (VideoView) findViewById(R.id.VideoView01);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "vid.mp4");
mc = new MediaController(this);
v.setMediaController(mc);
v.setVideoURI(uri);
v.start();
An alertbox appears saying that the video cannot be played.Do you have a solution to this .
thanks in advance
This is a linux filesystem permission issue. The location of the file is solely owned by your application. The MediaPlayer service ViewView relies on runs as a different "user" from a file system perspective.
The way I've solved this in the past is to create a custom VideoView extending SurfaceView that takes a FileDiscriptor as it's data source.
This side steps the issue by providing a connection to the data the is already open as far as the file system is concerned.
If your feeling frisky you could pull down the VideoView code from google and add a new setVideoFileDiscriptor method.

Video Streaming and Android

Today for one of my app (Android 2.1), I wanted to stream a video from an URL.
As far as I explored Android SDK it's quite good and I loved almost every piece of it.
But now that it comes to video stream I am kind of lost.
For any information you need about Android SDK you have thousands of blogs telling you how to do it. When it comes to video streaming, it's different. Informations is that abundant.
Everyone did it it's way tricking here and there.
Is there any well-know procedure that allows one to stream a video?
Did google think of making it easier for its developers?
If you want to just have the OS play a video using the default player you would use an intent like this:
String videoUrl = "insert url to video here";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoUrl));
startActivity(i);
However if you want to create a view yourself and stream video to it, one approach is to create a videoview in your layout and use the mediaplayer to stream video to it. Here's the videoview in xml:
<VideoView android:id="#+id/your_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
Then in onCreate in your activity you find the view and start the media player.
VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
String str = "the url to your video";
Uri uri = Uri.parse(str);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
Check out the videoview listeners for being notified when the video is done playing or an error occurs (VideoView.setOnCompletionListener, VideoView.setOnErrorListener, etc).

Categories

Resources