سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top