0

I'm looking to make a custom music player widget for my homescreen which will be attached to the stock music player on my phone. The controls on the widget will be very basic: play/pause, previous song and next song. It would also display the name of the song and the artist.

My question is if it is possible for your own widget to interact with the stock music player on an Android device. If yes, how could I achieve this? Are there any tutorials or articles on this around? I have found a couple of pages that mention something on this subject, but I can't find a clear answer.

Marjolein
  • 131
  • 1
  • 1
  • 5

1 Answers1

1

It depends on your phone and the default music player it uses. Different phones have different versions and even completely different music players. You can create an intent:

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);  
File musicFile = new File(SONG_URI);  
intent.setDataAndType(Uri.fromFile(musicFile), "audio/*");  
startActivity(intent);

and see whether the song will open with the stock music player.

linuxjava
  • 141
  • 2
  • 4
  • Thank you very much for your reply :). Since it depends on the phone and the default music player, I'm guessing that it would be difficult(impossible?) to make a universal widget? – Marjolein Sep 25 '13 at 20:02
  • 1
    The way this specific Intent would work is that it will attempt to use the best available player. Therefore even though you can make the widget, it is not guaranteed that the music file will play. – linuxjava Oct 03 '13 at 00:11