I have a link to a audio file. I don't want to create a object using my code for a Mediaplayer and play it, but instead I want to call the inbuilt MediaPlayer app of my android mobile. Is this possible at all. Any help is much appreciated.
Try this:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(audioFileUri, "audio/*");
startActivity(intent);
Or change the last line to startActivity(Intent.createChooser(intent, "play music")); to display a app chooser to finish the task.
I have used this piece of code and find that it doesn't work for the audio files for /raw folder. I guess this happens because the player can't get access to the resource from developer's package.
Related
I want to write some application to control android music player :)
For example when i shake phone -> player should change music next one. Is it possible without rooting my phone?
I think it is possible, here is a snippet for a performing playback through Intent.
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
or
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Source: Android launching music player using intent
You have to check if there are more Intents you can use by googleing (loading a playlist, etc.).
To control any 3rd party application it first have to be willing to let you to. It is usually done by exposing public API of any sort, so other app would know how to do that. If music player of your choice offers that, then "yes" is the answer. If it does not, then usually it means "no", and rooting is not necessarily a magical solution either. If there's no API or any other communication channel exposed (even non publicly) then achieving your goal would be tricky.
I want to use the systems audio/video player to play a sound from my raw folder but I keep on getting the same "No activity found to handle Intent" message (exception) when firing the intent.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://mypackagename/" + R.raw.audiofile), "audio/*");
startActivity(intent);
Any ideas? Thanks!
The way the intent system works is that your app is basically saying, "Hey Android, I have this url and I want to view it. Is there an app on the phone that will do that?"
For http urls, you've got your browser installed on the phone, for google play urls it'll show you the google play store as an option, etc etc. If you don't have an app on your phone that will handle audio resources (which there isn't one installed by default whatever that means for android).
Just like Dirk said, you have to use the MediaPlayer to play your resources. The MediaPlayer page is pretty sweet: http://developer.android.com/reference/android/media/MediaPlayer.html
Please try the following (Where soundfile is the name of the file in the raw folder without extension. Use only lowercase characters, please):
MediaPlayer player = MediaPlayer(this,R.raw.soundfile);
player.prepare();
player.start();
.
.
.
player.stop();
player.reset();
player.release();
player = null;
Found here.
In my open source app, I want to let users insert a picture/video/sound/etc. The user can either select an existing media from the SD card or use the device's hardware (take a photo, record a video, record a sound, draw on touchscreen) if they prefer to create a new media.
There are plenty of code snippets showing how to implement each of these things, but rather than re-inventing the wheel, is there a library that handles the whole activity of choosing a media file? I would just call this library, it would handle the UI, and return me the filepath to the media the user selected/created.
Here is how it could look like:
I am sure many apps would find this widget useful (CMS authoring, wysiwyg, sharing apps, rich chat, ...). As an LGPL (or public domain) component, I am sure it would be popular and gather a community of developers. Before I launch this project, is there already such a gadget?
I wrote a small Android Library Project, called aFileChooser, that aims to streamline the selection part of this process. It includes a built-in file explorer, and returns a File object after selection. You can also retrieve the image or video thumbnail, and use helper methods to get the URI and path.
Disclaimer: I haven't had a chance to test this with ICS, but it should function properly.
https://github.com/iPaulPro/aFileChooser
Finding an all-in-one solution with capture may not be as easy, as this is one of the areas where fragmentation is real.
For taking a picture, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult(intent);
For taking video, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.ACTION_VIDEO_CAPTURE );
startActivityForResult(intent);
For recording audio, use this Intent:
Intent intent = new Intent( android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION );
startActivityForResult( intent );
You, of course, would have to design the Activity to pick which action they would like to perform. See the linked documentation for retrieving the file path when the Activity returns.
OI File Manager for Android is an open file manager that seamlessly cooperates with other applications http://www.openintents.org/en/node/159
I need to play long audio files using the Android SDK. I am aware of the MediaPlayer framework shipped by Android, but I was wondering wether the built-in "Music Player" application could be invoked, so I don't have to write my own player GUI and code.
Yes, you can.
Set up an intent like this:
act=android.intent.action.VIEW dat=file:///mnt/sdcard/song_name.mp3 typ=audio/mpeg3
Action: VIEW
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri
.parse("file:///mnt/sdcard/song_name.mp3"),
"audio/mpeg3");
startActivity(intent);
I'm writing a small program, it can show and manager all files and folder in the android mobile. Now I get a problem need to help, when I click to a file icon, example a audio, i want the audio player can run and play it. Who can help me
using intent you can invoke another application for example
Intent i = new Intent(CurrentClass.this, NewClass.class);
startActivity(i);
For more information refer following link
link text
In Android, you use Intents to launch other programs.