I have an application that plays video files.
I have been using code for using Videoview and starting the Videoview manually to play video files. However, I just wanted to know if I can use the default media player or video player of android rather than creating or using the VideoView to play the file..
Please make comments if the question is not clear.
Thanks alot
Sure - just use an Intent with the file Uri.
File file = new File("fileUri");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);
Related
My App is having audio files in raw folder. Now whenever app gets launched these audio files should play using default music player. I tried below code App is crashing with "No Activity found to handle this intent".
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("companion.harman.com.ceshuclient/res/raw/fav.mp3"), "audio/*");
startActivity(intent);
The same audio files can be played using "MediaPlayer" object but that is not what exactly I'm trying to acheive.
Any sample code or links can be helpful.
Thanks in Advance.
Please try the following (Where mp3file is the name of the file in the raw folder without extension. Use only lowercase characters, please):
MediaPlayer player = MediaPlayer(this,R.raw.mp3file);
player.prepare();
player.start();
player.stop();
player.reset();
player.release();
player = null;
Here is the link of demo source code to play mp3 File
I'm developing an android app and I wanted to do something like that:
I have simple button and when I press it, the android native player pops with video up
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(Path to video file);
intent.setDataAndType(data, "video/mp4");
startActivity(intent);
use this if you don't want to use videoview
I am using this snippet to open a video using default Android Video Player:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://my.video/link.mp4"), "video/mp4");
startActivity(intent);
Now I want to display subtitle on the video, my subtitle is provided with a url, example http://my.subtitle/link.srt. I think there would be something simple like this:
intent.putExtra("subtitle", "http://my.subtitle/link.srt");
But it doesn't seem to be simple like that.
Could anyone show me how to do it? Thanks a lot.
I am using following code to play video for .3gp format and it works fine but I am facing problem while playing .sdp url.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("rtsp://stream.the.sk/live/musicbox/musicbox-3m.3gp"));
startActivity(intent);
I need to play rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_29.sdp format but it not work. Please help me. I tried to play it with VLC and MX Player.
Try this code in onCreate function. It will work i think.
VideoView view=new VideoView(this);
setContentView(view);
view.setMediaController(mediaController);
view.setVideoURI(Uri.parse("rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_29.sdp"));
view.start();
I want to play an MP3 file using the default Android player. I managed to get the file playing but it plays in the background. I want to have all the nice controls for pausing, playing, etc.
My code now is something like:
String link = "http://www.example.com/file.mp3";
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(link);
mp.prepare();
mp.start();
How can I do it that when this file begins to play to go to another screen with the player and all the nice controls?
The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:
Uri uri = Uri.parse("http://www.site.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
If the particular Action doesn't work, take a look here: http://developer.android.com/reference/android/content/Intent.html