Android :unable to play video - android

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));

Related

android videoview error 1, -2147483648

I am getting error while playing video from asset folder and raw folder.
MediaPlayer error (1, -2147483648)
VideoView error 1, -2147483648.
I tried from asset folder as.
private String SrcPath = "file:///android_asset/aaa.mp4"; //also tried aaaa.mp3
VideoView vv = (VideoView)findViewById(R.id.videoView1);
vv.setVideoPath(SrcPath);
MediaController controller = new MediaController(this);
controller.setAnchorView(vv);
vv.setMediaController(controller);
vv.requestFocus();
vv.start();
and for raw folder i used URI as :
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
vv.setVideoURI(video);
I got the same error message in both cases.
You can use software like avinaptic2 to get the video encoding information and make sure it matches the supported media formats in android.
A common problem I find is that videos are encoded with the wrong profiling. H.264 videos need to be encoded with Baseline level 3 or under to be played without errors or artifacts in Android.
I found the solution as I am able to play video on virtual device.
I replaced the line
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/aaa.mp4");
with
Uri video = Uri.parse("android.resource://com.usecontentprovider/raw/"+R.raw.aaa);
And its working
Using R.raw works fine but in some cases I still get the same error. Fortunately I found the solution to my problem: I had to call videoView.start() inside onPrepare().
You can check the correct answer here:
Android: 'Can't play this video'; MediaPlayer & VideoView Error 1 -38

Video not playing

I am using VideoView trying to play video. But when I use this code I have following error:
Sorry, this video cannot be played
What is wrong here?
VideoView vv = (VideoView) findViewById(R.id.videoView);
String path = "/mnt/sdcard/Video/1345467237098.m4v"
vv.setVideoPath(path);
This format is not supported, please check this url https://developer.android.com/guide/topics/media/media-formats.html
Th format in which the video is, is not supported by Android. I suggest you convert your video to .mp4 (which is supported).
I hope this helps.

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

I want to play a video from my assets or raw folder

I want to play a video from my assets or raw folder in my app in Android
using VideoView I am getting the error as video cannot be played
please anyone give me a solution.
Here is the code I used
VideoView vd = (VideoView)findViewById(R.id.Video);
Uri uri = Uri.parse("android.resource:" + R.raw.video);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
A few things to note:
You must copy the video into your project's res/raw folder.
It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename: my_video_file.mp4
When you work with this resource in code, you will reference through the generated R statics - it will have the file extension removed: R.raw.my_video_file
The Activity class has a helper method getPackageName() which can be used by your code when constructing the correct URI to your video.
VideoView vv = (VideoView)this.findViewById(R.id.videoView)
String uri = "android.resource://" + getPackageName() + "/" + R.raw.my_video_file;
vv.setVideoURI(Uri.parse(uri));
vv.start();
There is more information on this here.
You must include the package name in the uri:
Uri uri = Uri.parse("android.resource://[package]/raw/video")
or
Uri uri = Uri.parse("android.resource://[package]/"+R.raw.video);
Also, check out these examples.
There are so many ways to go wrong with VideoView ! Mainly because the logcat gives you no help, always giving error UNKNOWN.
I found this link was by far the best way to get started...
A complete description so you can't go wrong. Thanks go to the author...
http://androidexample.com/Play_Video_File_-_Android_Example/index.php?view=article_discription&aid=124&aaid=144
When we include a video resource in /resource/raw/ or assets/, by default, it looks for the .mp4 format, it won't accept .wmv files. If you read video file from external locations(like: /mnt/sdcard/demo.wmv) then it'll accept them.
Try:
AssetFileDescriptor afd = getAssets().openFd(fileName);
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
Make sure to write the file video name without extension.

Categories

Resources