So I created a directory on the internal storage like so:
File mediadir = getDir("tvr", Context.MODE_PRIVATE);
Then I download files from a server and save them inside the directory like this:
URL url = new URL(urlString);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is = url.openStream();
Log.d("DOWNLOAD NAME",name);
FileOutputStream fos = new FileOutputStream(mediadir+name);
etc
Then files are saved successfully, then next I want to play them like this:
String path = filelist[playListIndex].getAbsolutePath();
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoPath(path);
videoView.start();
where path is :
/data/data/com.mypackage/tvr/video.mp4
The file does not want to play with this error:
02-20 15:57:21.447: E/MediaPlayer(24143): error (1, -2147483648)
And on the device a message pops up : Cannot play video, Sorry this video cannot be player.
Is this a issue with rights or what? If it is, I was thinking because I created them, I have the rights to them?
CommonsWare has a good example on how to use the VideoView. Here is a link to someone who had a similar issue with video not wanting to play:
Playing a video in VideoView in Android
Also here is a video class of his example that I found useful when learning how to incorporate the VideoView:
https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java hope this helps.
I would also make sure that you have the permission settings in your manifest set:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The problem might be with the video encoding. Android FROYO and Gingerbread doesn't support H264 formats other than "Baseline" H264. So if your video is Mp4 & H264 encoded make sure its "AVC baseline" encoded. Use some tools like "Media info" in windows/Linux and check your video encoding. Convert the video to Baseline if possible.
An alternative workaround is to skip the Videoview and use a video play intent and redirect the playback to an app. User will be prompted to pick a player to handle the playback. Obviously if the video view cant play the file, the default player also wont be able to handle the file. you can choose some other installed player like Mx-Player which will stream the file perfectly.
Related
I have .h264 videos in server, how to decode that video and playing in android?
I am using the FFMPEG to play those videos but in FFMPEG sample it takes
the video from SD-card and successfully play's the video. I am using the
surface view to play those videos. My question is how to play .h264 video from amazon s3 server in android?
Thanks in advance.
Make your videos(files) in the s3 bucket public,
and use that public url, it will be accessible everywhere.
EDIT
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();
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 provide the appropriate permissions to your app (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
You can also use MediaPlayer. The Android developers site has a good tutorial here.
H.264
According to this, Android supports h.264 Baseline Profile playback. So your h.264 video is not Baseline Profile or possibly it contains an unsupported audio.
You should note that there are many h.64 flavors, so you should check your video file: http://www.niallkennedy.com/blog/2010/07/h264-video.html
You need make sure your H.264 video is in the codec that your Android device can accept, otherwise, you need re-encode it.
I have Complete solve my issue by this code May be It will Help you.
layout.xml
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
.class
String FileUrl="decoded url";
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(videoView);
Uri video = Uri.parse(FileUrl);
videoView.setMediaController(mediacontroller);
videoView.setVideoURI(video);
manifesto.xml
permitions
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I am trying to connect my android application with FTP Server which is broadcasting multiple streams using Dynamic Http Streaming at different bit rates.Flash Messaging Server(FMS) is using H.264 codec to broadcast video in flv format.On client side(Android) I am getting f4m(manifest (xml) file)) having diffrent streams.
I am unable to use the f4m file to fetch video in android from FMS.
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
Uri uri = Uri.parse(url);
// videoView.setVideoURI(uri);
videoView.setVideoPath(str);
MediaController mc = new MediaController(this);
//VMRuntime.getRuntime().setMinimumHeapSize(40);
mc.setAnchorView(videoView);
videoView.setMediaController(mc);
System.out.println("Max Memory - "+java.lang.Runtime.getRuntime().maxMemory());
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoView.start();
}
});
In above code I am trying to run video in Video View component by passing link of f4m file.
Flash encoder convert video into 3 file formats as listed below
.f4m (manifest files) - Bootstrap Info,Metadata, Bitrate, Flash Access license Server location
.f4f (fragment files) - extends the F4V format,MP4 fragment std
.f4x (index files) - binary
Kindly provide solution to play video on different android devices via Http Streaming in android.
Thanks in advance.
1) You have left something out of your code. What is str that you are passing to setVideoPath? (this is somewhat irrelevant, though...)
2) The MediaPlayer (and thereby VideoView) cannot play Flash video at all. It's simply not supported. It definitely won't understand an XML file, either, so passing it the f4m file is pointless.
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..
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"/>
I am working in android. I just used a video player. I am accessing video from my sdcard.
When i access video from myFolder then it works fine, but there are some folder which name are Japanese character. So whenever i want to access video from those folder then "Sorry, This video can not play" error is occurred.
This is my code which i am using:-
VideoView video = (VideoView) findViewById(R.id.videoId);
MediaController controller = new MediaController(this);
controller.setPadding(0, 0, 0, 55);
video.setVideoPath(URLDecoder.decode(sdCardUrl));
video.setMediaController(controller);
video.requestFocus();
video.start();
and this my path in which i am facing problem to video:-
url = /sdcard/.FileStorage/History/Myfilestorage/のフダ名/H.264(avc)_mp3_1000kbps_640x480_25fps.mp4
please suggest what should i do ?
Thank you in advance.
Try by converting that Japanese name in to UTF-8 format and then try to use it.
I have resolved my problem to trace the sequence of output of each line. I have done mistake that there is no need to decode url.
So the solution is to use following line:-
video.setVideoPath(sdCardUrl);
in place of video.setVideoPath(URLDecoder.decode(sdCardUrl));