<i id='p16aL'><tr id='p16aL'><dt id='p16aL'><q id='p16aL'><span id='p16aL'><b id='p16aL'><form id='p16aL'><ins id='p16aL'></ins><ul id='p16aL'></ul><sub id='p16aL'></sub></form><legend id='p16aL'></legend><bdo id='p16aL'><pre id='p16aL'><center id='p16aL'></center></pre></bdo></b><th id='p16aL'></th></span></q></dt></tr></i><div id='p16aL'><tfoot id='p16aL'></tfoot><dl id='p16aL'><fieldset id='p16aL'></fieldset></dl></div>

    <tfoot id='p16aL'></tfoot>

    <small id='p16aL'></small><noframes id='p16aL'>

      <bdo id='p16aL'></bdo><ul id='p16aL'></ul>
  • <legend id='p16aL'><style id='p16aL'><dir id='p16aL'><q id='p16aL'></q></dir></style></legend>

      1. Android 音乐播放器小部件

        时间:2023-09-08

          <legend id='AXt07'><style id='AXt07'><dir id='AXt07'><q id='AXt07'></q></dir></style></legend>

            <tfoot id='AXt07'></tfoot>
              <tbody id='AXt07'></tbody>
          1. <i id='AXt07'><tr id='AXt07'><dt id='AXt07'><q id='AXt07'><span id='AXt07'><b id='AXt07'><form id='AXt07'><ins id='AXt07'></ins><ul id='AXt07'></ul><sub id='AXt07'></sub></form><legend id='AXt07'></legend><bdo id='AXt07'><pre id='AXt07'><center id='AXt07'></center></pre></bdo></b><th id='AXt07'></th></span></q></dt></tr></i><div id='AXt07'><tfoot id='AXt07'></tfoot><dl id='AXt07'><fieldset id='AXt07'></fieldset></dl></div>
                  <bdo id='AXt07'></bdo><ul id='AXt07'></ul>
                • <small id='AXt07'></small><noframes id='AXt07'>

                  本文介绍了Android 音乐播放器小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发音乐播放器小部件(主屏幕小部件)..它只需要播放一首歌曲,(最好使用 MediaPlayer 类).但我不确定如何实现它.我对 Android 开发有点缺乏经验,就这么说吧.

                  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'm kind of inexperienced with Android development, just so that's mentioned.

                  我目前拥有的类扩展了AppWidgetProvider,我想让这个类处理音乐播放部分不是一个好主意,而是一个Service.如果有,怎么做?

                  The class I have so far extends AppWidgetProvider, and I guess it is not a good idea to let this class handle the music-playing part, but rather a Service. And if so, how?

                  另外,我有3个按钮:播放、暂停和停止,我可以在onReceive(...)中区分哪个按钮被按下了.

                  Furthermore, I have 3 buttons: play, pause and stop, and I can distinguish which one has been pressed in onReceive(...).

                  提前致谢!

                  这是课程.

                  public class MusicManager extends AppWidgetProvider {
                  
                      private final String ACTION_WIDGET_PLAY = "PlaySong";
                      private final String ACTION_WIDGET_PAUSE = "PauseSong";
                      private final String ACTION_WIDGET_STOP = "StopSong";   
                      private final int INTENT_FLAGS = 0;
                      private final int REQUEST_CODE = 0;
                  
                      @Override
                      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                              int[] appWidgetIds) {
                  
                          RemoteViews controlButtons = new RemoteViews(context.getPackageName(),
                                  R.layout.main);
                  
                          Intent playIntent = new Intent(context, MusicService.class);
                  
                          Intent pauseIntent = new Intent(context, MusicService.class);
                  
                          Intent stopIntent = new Intent(context, MusicService.class);
                  
                  
                          PendingIntent playPendingIntent = PendingIntent.getService(
                                  context, REQUEST_CODE, playIntent, INTENT_FLAGS);
                          PendingIntent pausePendingIntent = PendingIntent.getService(
                                  context, REQUEST_CODE, pauseIntent, INTENT_FLAGS);
                          PendingIntent stopPendingIntent = PendingIntent.getService(
                                  context, REQUEST_CODE, stopIntent, INTENT_FLAGS);
                  
                          controlButtons.setOnClickPendingIntent(
                                  R.id.btnPlay, playPendingIntent);
                          controlButtons.setOnClickPendingIntent(
                                  R.id.btnPause, pausePendingIntent);
                          controlButtons.setOnClickPendingIntent(
                                  R.id.btnStop, stopPendingIntent);
                  
                          appWidgetManager.updateAppWidget(appWidgetIds, controlButtons);         
                      }
                  }
                  

                  推荐答案

                  添加 到清单!

                  这篇关于Android 音乐播放器小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  <i id='Zbrv8'><tr id='Zbrv8'><dt id='Zbrv8'><q id='Zbrv8'><span id='Zbrv8'><b id='Zbrv8'><form id='Zbrv8'><ins id='Zbrv8'></ins><ul id='Zbrv8'></ul><sub id='Zbrv8'></sub></form><legend id='Zbrv8'></legend><bdo id='Zbrv8'><pre id='Zbrv8'><center id='Zbrv8'></center></pre></bdo></b><th id='Zbrv8'></th></span></q></dt></tr></i><div id='Zbrv8'><tfoot id='Zbrv8'></tfoot><dl id='Zbrv8'><fieldset id='Zbrv8'></fieldset></dl></div>

                  1. <small id='Zbrv8'></small><noframes id='Zbrv8'>

                    • <legend id='Zbrv8'><style id='Zbrv8'><dir id='Zbrv8'><q id='Zbrv8'></q></dir></style></legend>
                      • <bdo id='Zbrv8'></bdo><ul id='Zbrv8'></ul>
                        <tfoot id='Zbrv8'></tfoot>

                          <tbody id='Zbrv8'></tbody>