Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start the android standard mediaplayer (with its standard ui) with file to play via intent?

Tags:

android

I have an mp3 i save to sdcard if i start the MediaPlayer.play then it will just play it with no UI for forward,backward, so i just wanted to start the standard android media player so it will play my audio and in this way the user would be able interact with the media - forward backward etc. (I saw some ui projects for mediaPlayer but i really want the standard android media player, isn't there some intent to it?)

thanks

like image 498
Jas Avatar asked Feb 24 '11 07:02

Jas


People also ask

How do I play audio files on Android?

Prepare media file: To play a media file, you need to first prepare it i.e. you need to load the file for playback. Methods used for doing this are prepare(), prepareAsync(), and setDataSource(). Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method.

What is MediaPlayer in Android explain how do you play video with MediaPlayer?

You can play audio or video from media files stored in your application's resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection, all using MediaPlayer APIs. Note: You can play back the audio data only to the standard output device.

Which of the following method of the MediaPlayer class uses the SurfaceHolder object to display video content?

The Media Player requires a SurfaceHolder object for displaying video content, assigned using the setDisplay() method. The Surface View is a wrapper around the Surface Holder object. Note that we must implement the SurfaceHoler. Callback interface.


1 Answers

Standard way to do that:

Intent viewMediaIntent = new Intent();   
viewMediaIntent.setAction(android.content.Intent.ACTION_VIEW);   
File file = new File(objectFilePath);   
viewMediaIntent.setDataAndType(Uri.fromFile(file), "audio/*");   
viewMediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(viewMediaIntent);         

If you change type to "image/*" you can see individual images, with "video/*" you play video files.

like image 170
Zelimir Avatar answered Oct 02 '22 14:10

Zelimir