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();
Related
I downloaded the video from server url and store to sdcard, it's stored fine as a .mp4 format. But when i access this video from VideoView for playing video using MediaController, i'm getting can't play this video error. The folder name is Video.
MediaController mediaController = new MediaController(ImageTargets.this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
String sdpath=Environment.getExternalStorageDirectory().getAbsolutePath();
String video_path=sdpath+"Video" +"focusvideo.mp4";
videoView.setVideoPath(video_path);
videoView.start();
Environment.getExternalStorageDirectory() method return type is File instead of sdcard path as String. To get sdcard path call getAbsolutePath() of file as:
String sdpath=Environment.getExternalStorageDirectory().getAbsolutePath();
String video_path=str_path+"/Video/" +"focusvideo.mp4";
videoView.setVideoPath(video_path);
try this :-
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
I want to play a video from youtube in my app. But i dont want to use Youtube application for that. I prefer native videoplayer. I have written the below code for that. But nothing is happening. Only a black screen is displaying.
String link= getIntent().getExtras().get("url").toString();
VideoView videoView = (VideoView) findViewById(R.id.videoPlayer);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
Please help me. Thanks in advance.
just simply do it like that hope it's work:
String link= getIntent().getExtras().getString("url");
VideoView videoView = (VideoView) findViewById(R.id.videoPlayer);
Uri video = Uri.parse(link);
videoView.setVideoURI(video);
videoView.start();
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();
I want to play mp4 video using tag on Webview. I have few constraints for not to use HTML5 tag. I have looked code to play YouTube video on webview. But YouTube uses .flv format. I have .mp4 video to play.
Thanks in advance.
You could play the video directly, without a WebView:
VideoView videoView = new VideoView(this);
setContentView(videoView);
Bundle extra = getIntent().getExtras();
if (null != extra && extra.containsKey("url")) {
String url = extra.getString("url");
Uri uri = Uri.parse(url);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(uri);
videoView.start();
}
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();
}
});