예제 #1
0
  public void playNextSong(MusicItem musicItem) {
    String url = musicItem.audio;
    Logger.debug(TAG, ">>>" + "playNextSong:" + url);
    if (musicPlayBackCallback != null) {
      musicPlayBackCallback.onPreparing(currentItem);
    }
    mState = State.Stopped;

    relaxResource(false);
    try {
      setupMediaPlayerIfNeeded();

      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mediaPlayer.setDataSource(url);
      isStreaming = url.startsWith("http:") || url.startsWith("https:");

      songTitle = url;

      mState = State.Preparing;
      setupAsForeGround(musicItem);

      /** @see onPreparedListener */
      mediaPlayer.prepareAsync();

      if (isStreaming) {
        wifiLock.acquire();
      } else if (wifiLock.isHeld()) {
        wifiLock.release();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
 private void doToggleWifiLock() {
   if (mWifiLock.isHeld()) {
     mWifiLock.release();
   } else {
     mWifiLock.acquire();
   }
   ActivityCompat.invalidateOptionsMenu(this);
 }
 public void aquireWifiLock() {
   if (mWifiLock == null) {
     Log.d(TAG, "creating new WifiLock");
     mWifiLock = mManager.createWifiLock(WifiManager.WIFI_MODE_FULL, WIFI_LOCK_TAG);
   }
   if (!mWifiLock.isHeld()) {
     Log.d(TAG, "aquiring WifiLock");
     mWifiLock.acquire();
   }
 }
예제 #4
0
  void relaxResource(boolean isReleaseMediaPlayer) {
    stopForeground(true);
    if (isReleaseMediaPlayer && mediaPlayer != null) {
      mediaPlayer.reset();
      mediaPlayer.release();
      mediaPlayer = null;
    }

    if (wifiLock.isHeld()) {
      wifiLock.release();
    }
  }
예제 #5
0
 private void updateWifiLock(boolean isStarted) {
     WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
     if (null == wifiLock) {
         wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "fqrouter wifi hotspot");
     }
     if (isStarted) {
         wifiLock.acquire();
     } else {
         if (wifiLock.isHeld()) {
             wifiLock.release();
         }
     }
 }
예제 #6
0
  // call to acquire or release resources held by the WifiLock.
  // acquisition: every time the Monitor loop calls setClientStatus: computingStatus ==
  // COMPUTING_STATUS_COMPUTING || COMPUTING_STATUS_IDLE
  // release: every time acquisition criteria is not met , and in Monitor.onDestroy()
  public void setWifiLock(Boolean acquire) {
    try {
      if (wifiLock.isHeld() == acquire) return; // wifiLock already in desired state

      if (acquire) { // acquire wakeLock
        wifiLock.acquire();
        if (Logging.DEBUG) Log.d(Logging.TAG, "wifiLock acquired");
      } else { // release wakeLock
        wifiLock.release();
        if (Logging.DEBUG) Log.d(Logging.TAG, "wifiLock released");
      }
    } catch (Exception e) {
      if (Logging.WARNING) Log.w(Logging.TAG, "Exception durign setWifiLock " + acquire, e);
    }
  }
예제 #7
0
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   MenuItem wakeLockItem = menu.findItem(R.id.menu_toggle_wakelock);
   MenuItem wifiLockItem = menu.findItem(R.id.menu_toggle_wifilock);
   if (mWakeLock.isHeld()) {
     wakeLockItem.setTitle(R.string.disable_wakelock);
   } else {
     wakeLockItem.setTitle(R.string.enable_wakelock);
   }
   if (mWifiLock.isHeld()) {
     wifiLockItem.setTitle(R.string.disable_wifilock);
   } else {
     wifiLockItem.setTitle(R.string.enable_wifilock);
   }
   return super.onPrepareOptionsMenu(menu);
 }
예제 #8
0
 @Override
 public void stop(boolean notifyListeners) {
   mState = PlaybackStateCompat.STATE_STOPPED;
   if (notifyListeners && mCallback != null) {
     mCallback.onPlaybackStatusChanged(mState);
   }
   mCurrentPosition = getCurrentStreamPosition();
   // Give up Audio focus
   giveUpAudioFocus();
   unregisterAudioNoisyReceiver();
   // Relax all resources
   relaxResources(true);
   if (mWifiLock.isHeld()) {
     mWifiLock.release();
   }
 }
예제 #9
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   mViewFlipper.removeAllViews();
   unbindService(mTSConnection);
   if (mStopServiceOnFinish) {
     stopService(TSIntent);
   }
   mTermService = null;
   mTSConnection = null;
   if (mWakeLock.isHeld()) {
     mWakeLock.release();
   }
   if (mWifiLock.isHeld()) {
     mWifiLock.release();
   }
 }
예제 #10
0
  /**
   * Releases resources used by the service for playback. This includes the "foreground service"
   * status, the wake locks and possibly the MediaPlayer.
   *
   * @param releaseMediaPlayer Indicates whether the Media Player should also be released or not
   */
  private void relaxResources(boolean releaseMediaPlayer) {
    LogHelper.d(TAG, "relaxResources. releaseMediaPlayer=", releaseMediaPlayer);

    mService.stopForeground(true);

    // stop and release the Media Player, if it's available
    if (releaseMediaPlayer && mMediaPlayer != null) {
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
    }

    // we can also release the Wifi lock, if we're holding it
    if (mWifiLock.isHeld()) {
      mWifiLock.release();
    }
  }
 private synchronized void releaseWifiLockIfNecessary() {
   if (wifiLock != null && wifiLock.isHeld()) {
     wifiLock.release();
   }
 }
예제 #12
0
 public void ReleaseWifilock() {
   if (mWifilock.isHeld()) { // ?ж??????
     mWifilock.acquire();
   }
 }
예제 #13
0
 // 解锁WifiLock
 public void ReleaseWifiLock() {
   // 判断时候锁定
   if (mWifilock.isHeld()) {
     mWifilock.acquire();
   }
 }
 public void releaseWifiLock() {
   if (mWifiLock != null && mWifiLock.isHeld()) {
     Log.d(TAG, "releasing WifiLock");
     mWifiLock.release();
   }
 }