Android music player widget

后端 未结 2 654
天命终不由人
天命终不由人 2020-12-30 13:14

I\'m working on a music player-widget (home screen widget).. It only needs to play 1 song, (Preferably with the MediaPlayer class). But I\'m not sure how to implement it. I\

相关标签:
2条回答
  • 2020-12-30 13:49

    In the onUpdate(...) method of your AppWidgetProvider, use something like this to start a service (this example associates the service to a button click event):

    Intent intent = new Intent(context, MusicService.class);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
    
    // Get the layout for the App Widget and attach an on-click listener to the button
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
    views.setOnClickPendingIntent(R.id.button, pendingIntent);
    

    For more info look here

    0 讨论(0)
  • 2020-12-30 14:09

    Added <service android:name=".MusicService" android:enabled="true" /> to the manifest!

    0 讨论(0)
提交回复
热议问题