Exemple #1
0
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();
          String cmd = intent.getStringExtra(CommandPreference.CMDNAME);

          try {
            if (CommandPreference.CMDTOGGLEPAUSE.equals(cmd)
                || CommandPreference.TOGGLEPAUSE_ACTION.equals(action)) {
              setPlayState(KWPlayState.STATE_PAUSE);
            } else if (CommandPreference.CMDPAUSE.equals(cmd)
                || CommandPreference.PAUSE_ACTION.equals(action)) {
              musicHandler.sendEmptyMessageDelayed(WHAT_PLAY_PAUSE, MUSIC_SET_DELAYTIME);
            } else if (CommandPreference.CMDPLAY.equals(cmd)) {
              setPlayState(KWPlayState.STATE_PLAY);
            } else if (CommandPreference.CMDPREVIOUS.equals(cmd)
                || CommandPreference.PREVIOUS_ACTION.equals(action)) {
              setPlayState(KWPlayState.STATE_PRE);
            } else if (CommandPreference.CMDNEXT.equals(cmd)
                || CommandPreference.NEXT_ACTION.equals(action)) {
              setPlayState(KWPlayState.STATE_NEXT);
            } else if (CommandPreference.CMDSTOP.equals(cmd)) {
              exitKwApp();
            } else if (CommandPreference.CMDOPEN_MUSIC.equals(cmd)) {
              startKwApp();
              //					contiuneKwApp();
            } else if (CommandPreference.CMDFULL_CYCLE.equals(cmd)) {
              setPlayModel(KWPlayMode.MODE_ALL_CIRCLE);
            } else if (CommandPreference.CMDSINGLE_CYCLE.equals(cmd)) {
              setPlayModel(KWPlayMode.MODE_SINGLE_CIRCLE);
            } else if (CommandPreference.CMDORDER_PLAYBACK.equals(cmd)) {
              setPlayModel(KWPlayMode.MODE_ALL_ORDER);
            } else if (CommandPreference.CMDSHUFFLE_PLAYBACK.equals(cmd)) {
              setPlayModel(KWPlayMode.MODE_ALL_RANDOM);
            } else if (CommandPreference.CMDOPEN_DESK_LYRIC.equals(cmd)) {
              openDeskLyric();
            } else if (CommandPreference.CMDCLOSE_DESK_LYRIC.equals(cmd)) {
              closeDeskLyric();
            } else if (CommandPreference.ACTION_MUSIC_DATA.equals(action)) {
              String key = intent.getStringExtra(CommandPreference.MUSIC_KEY);
              searchOnlineMusic(key);
              // 播放音乐
              /*if(bundle != null){
              	TrackInfo track = (TrackInfo)bundle.getParcelable("track");
              	if(bundle != null && track != null){
              		playClientMusics(track.getTitle(), track.getArtist(), track.getAlbum());
              	}
              }*/
            } else if (CommandPreference.ACTION_MUSIC_LOCAL.equals(action)) {
              String path = intent.getStringExtra(CommandPreference.MUSIC_PATH);
              playLocalMusic(path);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
Exemple #2
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   if (intent != null) {
     String action = intent.getAction();
     if (action != null) {
       if (CommandPreference.CMDCLOSE_DESK_LYRIC.equals(action)) {
         closeDeskLyric();
       } else if (CommandPreference.CMDOPEN_DESK_LYRIC.equals(action)) {
         openDeskLyric();
       }
     }
   }
   return START_NOT_STICKY;
 }