Android 2.2: Problem playing video from SD card - android

When I try to play a video on my sd card, i get the error message "Sorry, this video cannot be played". Is there anything wrong with my code? None of the commented code seems to work.
public void PlayVideo(View view)
{
VideoView videoView = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// final String MEDIA_PATH = new String("/sdcard/yu5.mp4");
//videoView.setVideoPath(MEDIA_PATH);
//videoView.setVideoURI(Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"yu5.mp4")));
//videoView.setVideoURI(Uri.parse("file:///sdcard/yu5.mp4"));
videoView.setVideoURI(Uri.parse("http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=mfog"));
videoView.setMediaController(mediaController);
videoView.start();
}
When i stream from the web like in the code, the video is lagging a lot.

Please use Environment.getExternalStorageDirectory() for the root directory of external storage, not /sdcard, which is wrong on Android 2.2+ and other devices. Here is a sample project demonstrating playing back video from external storage.

Related

android Videoview not playing .sdp files what should i do?

I am making live tv channel streaming app.
But when i try to play the .sdp files in the android videoview it gives the error that "Sorry can't play this video".But it is playing .mp4 and .3gp videos successfully.
What should i do.I googled alot but in vain.
String VideoURL = "rtsp://pull.newclear.tv/live/livestream2_160p";
//"rtsp://pull.newclear.tv/live/livestream2_160p";
//.sdp links are also giving same error
//links of above type are not working
This is my code for videoview
MediaController mediacontroller = new MediaController(
VideoViewActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);

Cannot play video, android

I have used an mp4 video with a 400x760 resolution at 30fps and integrated it into an app using VideoView and MediaController
MediaController mediac;
VideoView video1;
mediac = new MediaController(this);
mediac.setAnchorView(video1);
video1 = (VideoView) findViewById(R.id.videoView1);
video1.setMediaController(mediac);
video1.setVideoPath("android.resource://video.test/raw/vid");
It plays fine on my ZTE Blade but on an Evo, GS2 and a Galaxy S , it says soryy, cannot play this video
Try with
video_view.setVideoURI(Uri.parse(path));
Sometimes passing directly as a string path doesn't work on some devices. The code which is working fine for me :
path = Environment.getExternalStorageDirectory() + "/file_name";
// Add controls to a MediaPlayer like play, pause.
MediaController mc = new MediaController(this);
video_view.setMediaController(mc);
// Set the path of Video or URI.
video_view.setVideoURI(Uri.parse(path));
// Set the focus.
video_view.requestFocus();
video_view.start();

Play video from an Url without webview

I have to play Dailymotion videos in an Android APP, but I must not do it in a WebView . VideoView class just accepts files streamed, and Dailymotion API has'nt got any resource for Android.
Does anyone know how to implement it?
Thanks!
String LINK = "Your_Link_Goes_Here";
setContentView(R.layout.mediaplayer);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
Try out this code..
VideoView is the best and in video view you can play streaming url also you can play the local files which you have on device sdcard or embeeded with in your app..
Refer this LINK this a sample
LINK

Android play a video with controller

I'm using the following code to play a .mp4 video on my android device. I have 3 problems,
using this code when I press the back button on the device the sound would still continoue to play
It doesn't play the video, only plays the sound!
I don't know how to get controller for the video so the user can stop the video, go back or forth on the video.
VideoView videoHolder = new VideoView(this);
videoHolder.setMediaController(new MediaController(this));
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaPlayer mediaPlayer = new MediaPlayer();
Uri myUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.video);
videoHolder.setVideoURI(myUri);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
videoHolder.requestFocus();
videoHolder.start();
1) Override onBackPressed in your activity:
#Override
public void onBackPressed() {
mediaPlayer.stopPlayback();
super.onBackPressed();
}
2) Is it a valid video format? Are you using emulator or a real device? If you use an emulator, try a real device instead. I recall similar issues before.
But I also notice: did you put your video in the drawable folder?
R.drawable.video
I don't think that will work, you cannot play videos from there. Use the resources/raw folder instead. btw: Audio can be played from assets folder directly, while video cannot; video can only played from the raw folder or if you copy it to the apps files folder (getFilesDir()) - or sdcard of course.
3) Why are you using a VideoView AND a MediaPlayer, instead of just a VideoView? You should get rid of the mediaPlayer and just use the VideoView. This line
videoHolder.setMediaController(new MediaController(this));
looks correct and sets the media controller, with which the user can seek in the video.
Programatically you can also use seekTo() to go back and forth in a video.
VideoView videoView =(VideoView)findViewById(R.id.vv01);
//specify the location of media file
Uri myUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.login_footage);
//Setting MediaController and URI, then starting the videoView
videoView.setVideoURI(myUri);
videoView.requestFocus();
videoView.start();
This worked for me

To play video files using MediaPlayer class in android

I want to play video files in my application which are part of my application.
for that i create 'raw' folder in 'res' and write following code in my activity.
MediaPlayer mp = MediaPlayer.create(VideoPlayer.this,R.raw.jeevrangala);
mp.start();
now i am testing it on emulator, but it does not displaying any thing.
is any one have solution to play video files in raw folder. please let me know.
Initial i was trying to play video files from raw folder. but cant run it. so i use another way to do this
VideoView video=(VideoView) findViewById(R.id.videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
//Uri uri = Uri.parse("android.resource://play.vedio/"+R.raw.dobeernotdrugs);
video.setKeepScreenOn(true);
video.setVideoPath("android.resource://one.two/raw/"+resource);
video.start();
video.requestFocus();
resource is file name which you want to play and one.two is package name your path may as like
"android.resource://package_name/raw/file_name"
You can use this code to run video on emulator.. for me it is working
VideoView videoHolder = (VideoView) findViewById(R.id.video_view);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.samplevideo);
videoHolder.setVideoURI(video);
videoHolder.start();
And please turn on your graphics acceleration for the emulator..

Categories

Resources