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
Related
Look here I want to make the same as vine app has. I tried to implement it by looking some answers at stackoverflow.com. But I could not. What about a size of video and quality? A size of app will increased? If I will use file that inserted in raw folder?
One of my apps contain a video as background. Placed in res/raw/ with 4,9 MB, 750x1334 Pixel, 20 seconds and H.264, AAC codec.
This of course increases the app size - even if you got minifyEnabled true / shrinkResources true for building the apk.
Example code (onCreate):
VideoView videoView = (VideoView) findViewById(R.id.videoView);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.background_video);
videoView.setDrawingCacheEnabled(true);
videoView.setVideoURI(uri);
videoView.requestFocus();
Don't forget to call videoView.pause/start at onPause/onResume
I tried to add a video path to an Android sample project - MediaPlayerDemo
I can playback the video when it stored in sdcard, the path is
"file:///sdcard/dcim/a.m4v"
But I can't playback the video when it stored in res/drawable. the path is
"android.resource://" +this.getPackageName () + "/" + R.drawable.a
I can read the id of the video in debug mode, but just can't replay the video.
How to solve it?
UPDATES
Thank you for the reply, so far i have tried:
put the video in assets, set path to "file:///android_asset/a.m4v".
put the video in raw, set path to
("android.resource://" +this.getPackageName () + "/" + R.raw.a) or ("android.resource://" +this.getPackageName () + "/raw/a)
but none of them can playback video.
My video is 1.8Mb, does it matter?
Create a new folder with name raw in res folder, if already created let it be. Copy your playable video file (e.g., myvideo.mp4) to raw folder. Use below code in your app.
String uriPath = "android.resource://"+getPackageName()+"/raw/myvideo";
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
I tested, its working for me. If the video is playable from sdcard then only it will play from raw folder, otherwise it will show a dialog box says Cannot play video.
try it and let me know what happened.
FYI, drawable is to store icons, images, drawables for the application. So You can put the same video either in assets or in raw folder.
I have found the solution, but not a straight forward way.
First, the file not found problem is not the path problem, it is because the permission problem.
To solve that, many people suggest copy the file into FileInputStream. But still got file not found problem.
But the File can be written to Inputstream. However, setDataSource() of Mediaplayer class does not acccept InpuStream. Therefore need to write the Inputstream to a temp File by BufferedOutputStream.
finally, setDataSource(tempfile_path) without error.
This question is quite old and still not answered well so here I will answer.
First of all, do not put videos in the assets folder. It is a bad practice. Create another folder (Preferably one named raw).
The second thing is that please do not use m4v format. Use a mp4 video.
Here is the code to insert video:
//Here it is assumed here that the file name of video in raw folder is demo
VideoView video = (VideoView) findViewById(R.id.videoView);
video.setVideoPath("android.resource//" + getPackageName() + "/" + R.raw.demo);
video.start();
Hope this clarifies your doubt!
I have two questions. I create movie player.
This is my code:
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoPath("/sdcard/747.3gp");
videoView.requestFocus();
videoView.start();
As you can see I want to play movies from sd card. To check my results I use emulator 2.2. So this is my first question: always when I want to play movie, he is stuck, but sound from movie is playing correctly. This is emulator error or maybe I am doing something wrong? And second question. I want play movies this way. I execute application and I get List of movies. I choose movie and this movie is playing. How I can do this? Can you write me example? I need help :)
For your first question, this should definitely be emulator's speed problem or problem with your file itself.
And answering your second question, you can go for samples like file explorer which displays all the files from sdcard in a listview and using which you can handle to show only video files.
Here is a example of file explorer,
http://android-er.blogspot.com/2010/01/implement-simple-file-explorer-in.html
http://androidsamples.blogspot.com/2009/06/displaying-list-of-video-files-stored.html
Extract the necessary code from the links and modify it accordingly.
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
I'm developing an app for the Archos 5 Internet Tablet. (With Android 1.6)
I want to start a video in a VideoView within my app. On my Android emulator the following code works fine but on my Archos 5 I always get an error:
Cannot play video
Sorry, this video cannot be played.
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//the VideoView will hold the video
VideoView videoHolder = (VideoView) findViewById(R.id.VideoView01);
//MediaController is the ui control hovering above the video (just like in the default youtube player).
videoHolder.setMediaController(new MediaController(this));
//assing a video file to the video holder
videoHolder.setVideoURI(Uri.parse("android.resource://mypackage/" + R.raw.testmovie));
//get focus, before playing the video.
videoHolder.requestFocus();
if(autoplay){
videoHolder.start();
}
Is there a way to run a VideoView on a archos 5?
I also tried to play the movie with the archos player. With the following code I get the error: "Cannot find the media file!".
String ACTION_LAUNCH_AVOS = "android.intent.action.LAUNCH_AVOS";
String avosCommand = "ACTION:video_play,url=videoentries:Video/testmovie.wmv,etype=resume";
final Intent startAvos = new Intent(ACTION_LAUNCH_AVOS,Uri.parse(avosCommand));
startAvos.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity(startAvos);
I put the video in the Video folder of the Archos. The video runs when I open it with the file browser.
I always get the error "Cannot find the media file!", no matter what url I use.
Is there a certain folder where I have to put the video so that it can be found? And how do I get the url to that certain folder?
It would be great if you could help me!
Thanks and BR,
Thomas