Video View not playing youtube video - android

I am trying to play a youtube video in a Video View.
I have laid out the xml like this:
<VideoView
android:id="#+id/VideoView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
and the code is like this:
setContentView(R.layout.webview);
VideoView vv = (VideoView) findViewById(R.id.VideoView);
MediaController mc=new MediaController(this);
mc.setEnabled(true);
mc.show(0);
vv.setMediaController(mc);
vv.setVideoURI(Uri.parse("http://www.youtube.com/watch?v=XS998HaGk9M"));
vv.requestFocus();
vv.showContextMenu();
vv.start();
I have added the permission within the manifest. When I load the application a dialog appears stating the video cannot be played.
I would appreciate any advice on this. Thanks

You specified wrong URI for the video.
http://www.youtube.com/watch?v=XS998HaGk9M is a web page, but not directly a video stream
Here is correct URI example:
rtsp://v6.cache4.c.youtube.com/CigLENy73wIaHwmh5W2TKCuN2RMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp
Also, this address can be obtained from YouTube API.
For example, from here: http://gdata.youtube.com/feeds/api/users/phonedog/uploads

While not an explicit answer I believe you need to launch an intent with a YouTube URL and let the OS handle it. That is, I don't think you can embed YouTube videos directly into your activities though I would love to be proven wrong.

Android webview and videoviews do not support play back of youtube videos in my experience.

Related

How to decode and play the .h264 video from amazon s3 server in android?

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" />

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..

Media player using YouTube?

I am developing a sample application using MediaPlayer.By using the raw resources folder,the video can be played.But I want to play through URL.How can I achieve this?
My code is:
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse("http://www.youtube.com/watch?v=T1Wgp3mLa_E");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
You need to get the correct streaming(rtsp) url rather than the link to the player page you are using. You can get this programmatically using the google data api
Once you have done that you would simply replace
"http://www.youtube.com/watch?v=T1Wgp3mLa_E"
with "rtsp://v8.cache1.c.youtube.com/CiILENy73wIaGQnxa4t5p6BVTxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
in your existing code and it should work.
Note: The quality of video, when streaming to your own videoview, can be very poor compared to how it looks when played on the youtube site or player app.
You have to rtsp links from gdata api :gdata api with this: http://gdata.youtube.com/feeds/api/videos?&max-results=20&v=2&format=1&q="+ URLEncoder.encode(activity.criteria)
Element rsp = (Element)entry.getElementsByTagName("media:content").item(1);
String anotherurl=rsp.getAttribute("url");
In gdata api only we are getting this type of links : rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
These are playing in VideoView.
My answer link :RTSP Links
In order to get better quality videos, I checked what these guys did. It helped me very very much!
I'm posting the link so you can checkout their project and use their code.

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

Video Streaming and Android

Today for one of my app (Android 2.1), I wanted to stream a video from an URL.
As far as I explored Android SDK it's quite good and I loved almost every piece of it.
But now that it comes to video stream I am kind of lost.
For any information you need about Android SDK you have thousands of blogs telling you how to do it. When it comes to video streaming, it's different. Informations is that abundant.
Everyone did it it's way tricking here and there.
Is there any well-know procedure that allows one to stream a video?
Did google think of making it easier for its developers?
If you want to just have the OS play a video using the default player you would use an intent like this:
String videoUrl = "insert url to video here";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoUrl));
startActivity(i);
However if you want to create a view yourself and stream video to it, one approach is to create a videoview in your layout and use the mediaplayer to stream video to it. Here's the videoview in xml:
<VideoView android:id="#+id/your_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
Then in onCreate in your activity you find the view and start the media player.
VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
String str = "the url to your video";
Uri uri = Uri.parse(str);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
Check out the videoview listeners for being notified when the video is done playing or an error occurs (VideoView.setOnCompletionListener, VideoView.setOnErrorListener, etc).

Categories

Resources