best way to use video viewer. and play videos - android

Is there any way I can play a video that has been stored in the raw file, without the use of the uri. If not how do i properly set the uri. Let's say i have file named movie and I want to play it with a videoviewer. How would i do this? Also would i have to write the data to the sd card. or can i just play it from the raw.
Why cant I just do
uri uri.parse("android.resources://"+this.getApplicationContext().getPackageName()+movie);
This is what I have it as now if you could can you point out the errors to me so i know and i wont have to have this problem any more
VideoView videoview = (VideoView) findViewById(R.id.videoView1);
videoview.setKeepScreenOn(true);
videoview.setVideoPath("android.raw://com.example.movievp8");
MediaController controller = new MediaController(videoview.getContext());
videoview.setMediaController(controller);
videoview.start();
videoview.requestFocus();

Here is something that works for me:
videoResource = R.raw.some_video;
String uri = String.format("android.resource://%s/%d", context.getPackageName(), videoResource);
animationCanvas = (VideoView) ui.findViewById(R.id.animation_canvas);
animationCanvas.setVisibility(View.VISIBLE);
animationCanvas.setVideoURI(Uri.parse(uri));
animationCanvas.setOnCompletionListener(this);
animationCanvas.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
animationCanvas.start();
}
});

Related

How to play mp4 in the raw of another application?

My app package name is com.example.app.a, I try to play the mp4 resource from application b com.example.app.b like this:
VideoView videoView = (VideoView) findViewById(R.id.picker);
videoView.setVideoURI(Uri.parse("android.resource://com.example.app.b/raw/keyboard_anim_theme"));
videoView.requestFocus();
videoView.start();
but the Can't play this video dialog shows. How can I play the mp4 in another application. Thanks a lot.
Have you tried with getIdentifier ?
check below code and check.
int rawId = getResources().getIdentifier("keyboard_anim_theme", "raw", "com.example.app.b");
String path = "android.resource://com.example.app.b/" + rawId;
videoView.requestFocus();
videoView.start();

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

How to play a mp4 videos in Android through Server

I am using following code to play mp4 videos which is stored in sever.... And i am get error like this->
This Video can not be played????
Uri video = Uri.parse("http://129.0.0.....");
MediaController mediaController = null;
mVideoView.setMediaController(mediaController);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://129.0.0....")));
mVideoView.setVideoURI(video);
mVideoView.setVideoPath("http://129.0.0......");
mVideoView.requestFocus();
mVideoView.start();
This might be helpful to you i have used this in android 2.3.3.
public void videoPlayer(String path, String fileName, boolean autoplay){
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//the VideoView will hold the video
VideoView videoHolder = new VideoView(this);
//MediaController is the ui control howering above the video (just like in the default youtube player).
videoHolder.setMediaController(new MediaController(this));
//assing a video file to the video holder
videoHolder.setVideoURI(Uri.parse(YOUR_SERVER_VIDEOFILE_URL));
//get focus, before playing the video.
videoHolder.requestFocus();
if(autoplay){
videoHolder.start();
}
}
Always pass the mp4,3gp etc video format link in URI.Try this code:
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp"));
videoView.requestFocus();
videoView.start();

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

How to assign utube video url to android media player

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

Categories

Resources