Stream music through URL on pre installed music player - android

I am trying to play a music file located on Internet with some URL like "http://......../music.mp3"
I am using the following code
Uri myUri = Uri.parse("http://..../music.mp3");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(myUri, "audio/*");
startActivity(intent);
this code is not playing music in any installed music player, I think it passes the URL so music player is unable to play it.
I dont want to play music on my app. can anyone give me a hint how to implement it.

Related

open Media Player to reproduce mp3

I have a list of mp3 files, and i would to reproduce it into device media player, in my case Play Music.
I've this code:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
context.startActivity(intent);
but this code don't open full media player (and reproduce file), but just a little player over my activity.
How can i open full media player and reproduce audio?

android playing audio stream to default or installed music player

I am developing an app where I can stream audio from http get requests and play it to the default android music player or installed music player? I have no idea how to do it?
Thanks.
Do this way
Uri uri = Uri.parse("http://www.example.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

Android: how to play an mp3(URL) file using the any of the installed apps

I have URL poins to mp3 file
what I need is when the user click a certain button in my layout I want the android OS to display a list of the installed apps that can handle this URL
can this done or I should use the MediaPlayer class?
To open a url, android system will show browsers list. But i think you need apps which can stream music. I dont think there is any system app that can do it. or else you can download music when user clicks on button and then open music players by media intent or mediaplayer class.
MediaPlayer mMediaPlayer = new MediaPlayer();
FileInputStream fileStream = new FileInputStream("your song.mp3");
mMediaPlayer.setDataSource(fileStream.getFD());
Try this

Intent to play sound from raw folder

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.

How to access the default MediaPlayer

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.

Categories

Resources