Example #1
1
    @Override
    public void handleMessage(Message msg) {
      AudioService service = getOwner();
      if (service == null) return;

      switch (msg.what) {
        case SHOW_PROGRESS:
          if (service.mCallback.size() > 0) {
            removeMessages(SHOW_PROGRESS);
            service.executeUpdate(false);
            sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
          }
          break;
      }
    }
Example #2
1
    @Override
    public void handleMessage(Message msg) {
      AudioService service = getOwner();
      if (service == null) return;

      switch (msg.getData().getInt("event")) {
        case EventManager.MediaPlayerPlaying:
          Log.i(TAG, "MediaPlayerPlaying");

          if (service.mCurrentMedia == null) return;
          String location = service.mCurrentMedia.getLocation();
          long length = service.mLibVLC.getLength();
          DatabaseManager dbManager = DatabaseManager.getInstance(VLCApplication.getAppContext());
          Media m = dbManager.getMedia(VLCApplication.getAppContext(), location);
          /**
           * 1) There is a media to update 2) It has a length of 0 (dynamic track loading - most
           * notably the OGG container) 3) We were able to get a length even after parsing (don't
           * want to replace a 0 with a 0)
           */
          if (m != null && m.getLength() == 0 && length > 0) {
            Log.d(TAG, "Updating audio file length");
            dbManager.updateMedia(location, DatabaseManager.mediaColumn.MEDIA_LENGTH, length);
          }

          service.changeAudioFocus(true);
          service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
          if (!service.mWakeLock.isHeld()) service.mWakeLock.acquire();
          break;
        case EventManager.MediaPlayerPaused:
          Log.i(TAG, "MediaPlayerPaused");
          service.executeUpdate();
          // also hide notification if phone ringing
          service.hideNotification();
          service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
          if (service.mWakeLock.isHeld()) service.mWakeLock.release();
          break;
        case EventManager.MediaPlayerStopped:
          Log.i(TAG, "MediaPlayerStopped");
          service.executeUpdate();
          service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
          if (service.mWakeLock.isHeld()) service.mWakeLock.release();
          break;
        case EventManager.MediaPlayerEndReached:
          Log.i(TAG, "MediaPlayerEndReached");
          service.executeUpdate();
          service.next();
          if (service.mWakeLock.isHeld()) service.mWakeLock.release();
          break;
        case EventManager.MediaPlayerVout:
          if (msg.getData().getInt("data") > 0) {
            service.handleVout();
          }
          break;
        case EventManager.MediaPlayerPositionChanged:
          float pos = msg.getData().getFloat("data");
          service.updateWidgetPosition(service, pos);
          break;
        default:
          Log.e(TAG, "Event not handled");
          break;
      }
    }