How to assign utube video url to android media player - android

I want that when i will pass the utube url to media player it will automatically load the video and play in it.
Example: http://www.youtube.com/watch?v=WAG8e_53le4
This type of url i want to play in android media player

If you want to play YouTube video in VideoView, you need rtsp url from youtube.
You can get the rtsp from Youtube Gdata feed. Although I find it quite strange that sometime the rtsp isn't available in the feed.

This works for me. It starts when the activity is created.
progressDialog = ProgressDialog.show(StevenBActivity.this, "", "Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//video "DON'T DO IT" 1,315 views
video_url = "rtsp://v2.cache4.c.youtube.com/CjgLENy73wIaLwlPMIWk2hSzNRMYJCAkFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg6KnB9MbH8sVODA==/0/0/0/video.3gp";
//http://www.youtube.com/watch?v=NJNzBQvJpUI&list=UUy_BjNhdQh9-bfRuzuk53pg&index=9&feature=plcp
try {
final VideoView videoView =(VideoView)findViewById(R.id.videoView1);
mediaController = new MediaController(StevenBActivity.this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
}

Related

I am working on videoview in android some specific videos are not working in video view

Almost every videos are playing in my videoview but some specific URL are not playing every time in my videoview while they are perfectly working in system web browser and mobile webbrowser:
Here is my error code:
MediaPlayer: Couldn't open file on client side, trying server side
11-22 16:28:15.269 15589-15609/com.videodemo E/MediaPlayer: error (1, -2147483648)
11-22 16:28:15.269 15589-15589/com.videodemo E/MediaPlayer: Error (1,-2147483648)
Please check with this.:---
// Find your VideoView in your video_main.xml layout
videoview = (VideoView) findViewById(R.id.VideoView);
// Execute StreamVideo AsyncTask
// Create a progressbar
pDialog = new ProgressDialog(VideoViewActivity.this);
// Set progressbar title
pDialog.setTitle("Android Video Streaming Tutorial");
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
try {
// Start the MediaController
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);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoview.start();
}
});
}
After a bit of investigating, i think the problem lies with your video codec format. Since android videoview does not support all kinds of codecs that are out there, it is very much possible that the video you are trying to play is not supported by android-sdk.
Although android-sdk could've given a specific error so that we can
understand why the video is not playing.
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(videoview);
Uri video = Uri.parse("android.resource://your package name/" + R.raw.Your Video);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
}
catch (Exception e)
{
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoview.start();
}
});
`

Is there way to play HTML5 video in native media player Android?

I have project which have html5 video needed to play in native Android Player similar how it does on iOS.
Is there way to implement it?
I will be grateful for any adivice or solution.Thanks.
Yes if you bring some codecs for your file format (.Flv I think) because android does not have those codes.
For a mp4 file use something like this:
try {
setContentView(R.layout.videodisplay);
String link="http://s1133.photobucket.com/albums/m590/Anniebabycupcakez/?action=view& current=1376992942447_242.mp4";
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}

Android VideoView won't Play

So I'm trying to play a basic avi video in android, it seems to run fine on Windows Media Player, VLC, etc. so it doesn't look like it's requiring any complicated codecs. I have a video view in my app and that's it, and I have my video in my resources directory under:
res/raw/my_video.avi
This is the code I'm using to load my video:
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.start();
And it does not work. I get a popup saying "Can't play this video" along with a logcat message:
03-10 01:42:12.102: E/(185): Failed to open file 'android.resource://com.securespaces.android.bootstrap/2130968576'. (No such file or directory)
03-10 01:42:12.102: E/MediaPlayer(9737): error (1, -2147483648)
03-10 01:42:12.142: E/MediaPlayer(9737): Error (1,-2147483648)
I'm running this on a Nexus 5 running 4.4.2 stock by the way. I'm following instructions that I found in other stack over flow questions here: How to play videos in android from assets folder or raw folder? with some minor tweaks so that I am using a VideoView that I grab from a layout file.
I'm really stumped as to why this isn't working. I've browsed through a few questions on this subject, but this feels like something that should be a duplicate. I'm running this on a Nexus 5 running 4.4.2 stock by the way.
To clarify the question, I'm wondering what I am doing wrong, or is there an alternative for just playing a simple AVI video?
Write your package name statically and check whether video plays or not.
Try out as below:
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://com.securespaces.android.bootstrap/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
Implement this :
public static void getVideoFromRaw(String rawPath) {
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURL
Uri mVideo = Uri.parse(rawPath);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
mVideoview.requestFocus();
mVideoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
mVideoview.start();
}
});
mVideoview.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
}
});
}
Thanks

Live audio streaming with Android 2.x

I need to play a live stream on devices with 2.x and greater versions. This states that it's impossible to play live streams on devices with Android 2.x.
What're my options here ? Especially I'm interested in streaming audio - what format should i pick and in conjunction with which protocol ?
P.S. I've tried Vitamio - don't want to make customers download third party libraries.
UPD
How come I can play this stream "http://188.138.112.71:9018/" ?
try this example for RTSP streaming (the url should support RTSP) for video change the code to support just audio
public class MultimediaActivity extends Activity {
private static final String RTSP = "rtsp://url here";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multimedia);
//***VideoView to video element inside Multimedia.xml file
VideoView videoView = (VideoView) findViewById(R.id.video);
Log.v("Video", "***Video to Play:: " + RTSP);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
Uri video = Uri.parse(RTSP);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
}
EDIT:
Live Audio streaming using MediaPlayer in Android
Live Audio streaming in android, from 1.6 sdk onwards is become so easy. In setDataSource() API directly pass the url and audio will play without any issues.
The complete code snippet is,
public class AudioStream extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "http://www.songblasts.com/songs/hindi/t/three-idiots/01-Aal_Izz_Well-(SongsBlasts.Com).mp3";
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(url);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.prepare();
mp.start();
} catch (Exception e) {
Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
}
}
}
You can use RTSP protocol which is supported by Android native media player.
player = new MediaPlayer();
player.reset();
player.setDataSource(intent.getStringExtra("Path"));
player.prepare();
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
Where path would be your rtsp audio streaming url.

Unable to play Youtube stream via VideoView. How do I fix this?

I'm trying to play a youtube video using VideoView. It gives me "can not play video" error. What am I doing wrong in the code below. The URL I am using is just regular youtube URL : http://www.youtube.com/watch?v=q7u30Li-oOc
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.main);
//init components for use
mVideoView = (VideoView) findViewById(R.id.video);
text = (TextView)findViewById(R.id.textView1);
//Get URI data from VideoDemo activity
Bundle uristream = getIntent().getExtras();
videoUri = uristream.getString("urivalue");
//set Texfield to URI string
text.setText(videoUri);
//mVideoView.setVideoPath(videoUri);
//provide VideoView component with file path and play
mVideoView.setVideoURI(Uri.parse(videoUri));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();
}
no need to create separate video view we can play youtube videos directly by using this intent
startActivity(newIntent(Intent.ACTION_VIEW,Uri.parse("video url")));
It is because your phone does not support MP4 videos. Try using video players like daroon which play all sort of videos. First test your application if you able to play videos with .3gp extension. If you cannot, then the problem is with your code.
Uri video = Uri.parse(videoUri);
videoView.setMediaController(mediaController);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(videoUri)));
videoView.setVideoURI(video);
videoView.setVideoPath(videoUri);
videoView.requestFocus();
videoView.start();
For more info, go through android media format support
I ran the same exact code above , but instead of using a youtube url for the videoUri. I uploaded a video to my site database and set videouri to that URL. IT WORKED!! Apparently VideoView and Youtube streams do not work well together.
mVideoView.setVideoURI(Uri.parse(videoUri));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.start();

Categories

Resources