Issue on Android Video View its not working - android

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

Related

Play a video on Android using a videoview container

Im trying to understand how to add video to my application using the VideoView container but so far I've never been able to view a video and all i receive is an error 'Can't play this video'.
I have a simple method that load's the video:-
private void setupVideo() {
VideoView videoView = (VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("video/Test_Movie.m4v");
videoView.start();
}
I have tried converting the video to many H264, H263 , 3gp formats but I can find anything that works.I even have downloaded a video that said worked in a book i have but still doesn't work.
any help appreciated!
thx.

Streaming Youtube video in android VideoView

I am working on an app which stream youtube videos.
Here is my code snippet :
MediaController mediaController = new MediaController(PlayVideo.this);
mediaController.setAnchorView(videoView_Video);
mediaController.setMediaPlayer(videoView_Video);
Uri videoUri = Uri.parse(url);
videoView_Video.setMediaController(mediaController);
videoView_Video.setVideoURI(videoUri);
videoView_Video.requestFocus();
videoView_Video.start();
mediaController.show();
My URI:
videoUri = rtsp://v2.cache8.c.youtube.com/CiILENy73wIaGQm-LZitWsUGKxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
Now I Am getting an error as below:
1. http youtube = false, scheme = rtsp
2. Couldn't open file on client side, trying server side
3. Error (1,-2147483648)
4. Error: 1,-2147483648
And a dialog with a message :
Please suggest any answer to overcome this.
Use the proper API instead of manually parsing and finding videos.
https://developers.google.com/youtube/android/player/
you just import the proper YouTubeVideoPlayer and things work fine.
ps.: I don't suggest using this in a ViewPager, I only had problems with that.
Google has a YouTube Android Player API that enables you to incorporate video playback functionality into your Android applications. The API itself is very easy to use and works well. For example, here is how to create a new activity to play a video using the API.
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, "<<YOUTUBE_API_KEY>>", "<<Youtube Video ID>>", 0, true, false);  
startActivity(intent);
See this for more details.

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.

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