Movie Player Android - android

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.

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

Android SDK - Media Player Video from URL

I've tried to find a simple tutorial which explains how to load a video from a URL into the android media player but unfortunately I couldn't find any!
I have tried several things to try get it working but still no luck.
What is the best way to have a MediaPlayerActivity just load a video from a URL?
Thanks
EDIT:
I have tried the following code as suggested:
VideoView videoView = (VideoView) findViewById(R.id.your_video_view);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("url-here"));
videoView.start();
It just crashes when I go to this activity.
You can use a VideoView. Here is an example:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
//Use a media controller so that you can scroll the video contents
//and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(videoUrl));
videoView.start();
EDIT
You should provide the URI (having a String url variable, where it has the url of the video) with this code Uri.parse(url). And also be sure if the url is appropriate. Also, have you provided the appropriate permissions to your app, as AkashG suggested, (since it uses the internet you will need to add <uses-permission android:name="android.permission.INTERNET" > in your app's Manifest.xml)? Finally you should define your activity MediaPlayerActivity in in your app's Manifest.xml
End of EDIT
You can also use MediaPlayer. The Android developers site has a good tutorial here.
you can load video from url as:
VideoView videoView = (VideoView) findViewById(R.id.view);
MediaController controller = new MediaController(this);
videoView.setVideoPath("url of the video");
videoView.setMediaController(controller);
videoView.start();
Add internet permission in manifest file.
I think you can find useful thinks Here.. about playing video from different sources.
If your using Emulator ,
First, do not use the emulator for testing video playback. Its ability to handle video playback is very limited. Use an actual Android device.
Second, always check LogCat (adb logcat, DDMS, or DDMS perspective in Eclipse) for warnings when you run into multimedia problems. OpenCORE -- the multimedia engine used by Android -- has a tendency to log error-level conditions as warnings.
For example, your video file may not be set up for progressive download, which is required for HTTP streaming. On Linux, you can patch up MP4 videos for progressive download by installing MP4Box and running MP4Box -hint .
Hope this explanation works for you..

How to play videos from SD Card

I was creating a simple app which stream videos from net and I made it but now I want to change the code so that I can play video files from my SDCard
original code:
Uri vidFile = Uri.parse("MY SITE HERE");
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
videoView.setVideoURI(vidFile);
videoView.setMediaController(new MediaController(this));
videoView.start();
So please help me with changing the code so that it can play videos from my mobile memory card.
The videoView.setVideoURI(vidFile); method needs to be replaced by the videoView.setVideoPath(path); method.
Here path specifies the path of the video file on the SDCARD.
This path can be easily retrieved using the MediaStore.Video.Media.DATA property of that video file or by just entering the songpath statically as /sdcard/songname.
Uri vidFile = Uri.parse(
Environment.getExternalStorageDirectory().getAbsolutePath()+"filename");
...
the rest of the code will be same.
In place of
videoView.setVideoUri(vidFile)
use
videoView.setVideoPath("/sdcard/SONG.").
Let me know.
these links may help you:
Playing 3gp video in SD card of Android
how-play-video-and-audio-android
Using VideoView to play mp4 from sdcard
I also tried your code and got same error message but when I tried with video path with no blank space in path or name, it worked well. Just give it a try.
e.g,
file path "/mnt/sdcard/Movies/Long Drive Song - Khiladi 786 ft. Akshay Kumar_Asin-YouTube.mp4"
gave the error but file path "/mnt/sdcard/Movies/Khiladi.mp4" worked well.
I know is is old but if it can help. add this to your manifest
<uses-permission android:name="com.android.externalstorage.ExternalStorageProvider"/>

Issue on Android Video View its not working

I'm playing YouTube from URL, but when I play the video it shows the following error:
unable to open video
I'm using this code:
video =new VideoView(this);
video.setVideoURI(path);
System.out.println("my path"+path);
ctlr = new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();`
The path is correct. I checked on the Web also. Why am I getting an error like that?
The links are like: http://www.youtube.com/v/8B-Vu94Sd4M?f=videos&app=youtube_gdata
You can't simply give the VideoView a Youtube URL and expect it to play the video. This seams to be impossible at all (see here).
However, you might want to use a YouTube Intent and let the System handle it: Link

Android not playing Video .mp4

I have prepared a code to just play a simple mp4 file from my res folder. The coding is something like this:
public class VideoPlayer extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView video = (VideoView)findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://company.software.myapp/"
+ R.raw.myvideo);
MediaController mc = new MediaController(this);
video.setMediaController(mc);
video.setVideoURI(uri);
//video.requestFocus();
video.start();
}
}
Now though there is no error in playing. The activity automatically generates a dialog saying "sorry this video cannot be played", but I can hear the audio and it plays till end. What is the problem?
Thanx a lot commonsware.com... but i found the solution to the problem... And astonishingly its the PC processor which is the culprit... I checked n a higher configuration and guess wat... it worked perfectly fine... though sometimes if we do some processing in the background the dialog box does come up but on clicking ok it starts playing the video after some time...
But i confirm that this technique of playing file from resource is ok as far as i know...
sorry to waste ur precious time in a mundane hardware problem... but hope it'll be useful for other people who get this problem...
Android supports 3gp and mp4 format, but still sometimes there are problems in playing an mp4 content.
one thing what I have found out from my research is that, this might be because the resolution problem with the video.
I think that you should re-size the resolution of your mp4 video. This might help.
I have not attempted to play a video clip out of a resource, and I am not certain that it works.
As a test, put the video clip on the SD card and use that as the source of your video.
If you get the same symptoms, then either the MP4 file has issues or it is something with your test environment (e.g., you are using the emulator and don't have a quad-core CPU).
If the SD card test works, though, then I suspect the problem is packaging it as a resource.

Categories

Resources