Reputation: 273
I just need to start the SERVICE of default Music player. I can play the song if the service is started but have no idea how to start the service of music player
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "play");
context.sendBroadcast(i);
Upvotes: 0
Views: 325
Reputation: 47817
Try this
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
or
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
or You can simply pass the url to Media Player like this,
Uri myUri = Uri.parse("your url here");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(myUri, "audio/*");
startActivity(intent);
Extracted from https://snipt.net/Martin/android-intent-usage/
I haven't tested myself.
Upvotes: 1