문제

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