Am trying to play videos which i have in my sd card but it is showing an error that video cannot be played.. My code is
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mPath = (EditText) findViewById(R.id.path);
mPath.setText("mnt/sdcard/music/jelly jamm.3gp");
Can anyone help me.. I tried all the posts in stack overflow but still getting same error
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imgUri = Uri.parse("file://mnt/sdcard/music/jelly jamm.3gp");
intent.setDataAndType(imgUri, "video/mp4");
startActivity(intent);
try like this. Hope this will give you some solution.
Use this code to play video from sdcard
VideoView vv = (VideoView)findViewById(R.id.videoView1);
File root;
root = Environment.getExternalStorageDirectory();
Log.d("FILEPATH1", root.toString());
String path =root.toString()+"/music/jelly jamm.3gp";
MediaController mc= new MediaController(getApplicationContext());
vv.setVideoPath(path);
vv.setMediaController(mc);
vv.requestFocus();
vv.start();
If you post the error you are getting we can help you...
May be your video is incompatible with Android. Try it with a different video. like any .mp4 video definitely works with Android. If that video works, and yours does not, then your video is not compatible with Android.
and do test this on a device. Video playback on the emulator requires too much power.
Related
I'm using this piece of code to try and open a .mp4 video:
VideoView videoView=(VideoView)findViewById(R.id.videoView1);
MediaController mediaController=new MediaController(this);
mediaController.setAnchorView(videoView) ;
videoView.setVideoPath("R.raw.videoname");
videoView.setMediaController(mediaController) ;
videoView.start();
However, whenever I try to run the app, I get a message saying "Can't play this video". I am using a new Nexus 7 tablet if that means anything.
Also, when I try to open the same file that I have stored in with my movies, the video runs perfectly normally when I use Gallery or Video Player to open it.
Any help is much appreciated.
File file = new File(getFilePath());//file path of your video
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "*/*";
Uri uri = Uri.parse("www.google.com");
Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
Uri data = Uri.fromFile(file);
type_intent.setDataAndType(data, type);
startActivity(type_intent);
Make sure there will be no space in video name, otherwise it will not
be played by android VideoView.
If not solved then let me know.
Hello i have one rtsp live video url, I have't know how to play this live stream live Video url.
i am working on android sample application. Please share your guide with me.
Following code using to play live streaming url.
Don't have any idea, how to get live video streaming. Please suggest me any idea to send to live video stream to server.
below are my sample code.
public class MultimediaActivity extends Activity {
private static final String rtspURL = "rtsp://URL_IP:PORT+video+FileName";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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(rtspURL);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
}
please suggest me, What should i do..?
Thank you..
Use this code for playing on player
Intent i1 = new Intent (Intent.ACTION_VIEW ,Uri.parse(rtspURL));
startActivity(i1);
and use this code for videoview
VideoView v1 = (VideoView)findViewById(R.id.videoView1);
v1.setVideoPath(rtspURL); //your rtspurl
v1.start()
this work for me ...
Please tell me why this would work on with MediaPLayer and not in videoView? And how to make it work with a video view?
Videos are downloaded form an API and saved in this folder I created:
File mediadir = cw.getDir("tvr", Context.MODE_PRIVATE);
VideoView
final Uri uri = Uri.parse(path);
// path = /data/data/com.foo.app/tvr/video.mp4
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoURI(Uri.parse(path));
videoView.start();
Error VideoView Sorry, this Video cannot be player and error (1, -2...)
MediaPlayer --- THIS WORKS
FileInputStream fileInputStream = new FileInputStream(path);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fileInputStream.getFD());
pl.prepare();
pl.start();
The basic reason is the MODE_PRIVATE, which disallow VideoView and MediaPlayer from playing non-World Readable files, unless you pass the FD as you have.
Here's a more detailed explanation
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();
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();
}
});