Exemple #1
0
 private VlcMediaPlayer(PlayerEventProcessor processor) {
   Log.v(TAG, Logging.getCurrentMethodName(processor));
   mEventsProcessor = processor;
   try {
     mLibVlcInstance = LibVLC.getInstance();
   } catch (LibVlcException e) {
     e.printStackTrace();
     mEventsProcessor.onError();
   }
   EventManager.getInstance().addHandler(mVlcEventHandler);
 }
Exemple #2
0
  @Override
  public void onCreate() {
    super.onCreate();

    // Get libVLC instance
    try {
      mLibVLC = LibVLC.getInstance();
    } catch (LibVlcException e) {
      e.printStackTrace();
    }

    Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler());

    mCallback = new HashMap<IAudioServiceCallback, Integer>();
    mMediaList = new ArrayList<Media>();
    mPrevious = new Stack<Media>();
    mEventManager = EventManager.getInstance();
    mRemoteControlClientReceiverComponent =
        new ComponentName(getPackageName(), RemoteControlClientReceiver.class.getName());

    // Make sure the audio player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

    IntentFilter filter = new IntentFilter();
    filter.setPriority(Integer.MAX_VALUE);
    filter.addAction(ACTION_REMOTE_BACKWARD);
    filter.addAction(ACTION_REMOTE_PLAYPAUSE);
    filter.addAction(ACTION_REMOTE_PLAY);
    filter.addAction(ACTION_REMOTE_PAUSE);
    filter.addAction(ACTION_REMOTE_STOP);
    filter.addAction(ACTION_REMOTE_FORWARD);
    filter.addAction(ACTION_REMOTE_LAST_PLAYLIST);
    filter.addAction(Intent.ACTION_HEADSET_PLUG);
    filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(serviceReceiver, filter);

    final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean stealRemoteControl = pref.getBoolean("steal_remote_control", false);

    if (!Util.isFroyoOrLater() || stealRemoteControl) {
      /* Backward compatibility for API 7 */
      filter = new IntentFilter();
      if (stealRemoteControl) filter.setPriority(Integer.MAX_VALUE);
      filter.addAction(Intent.ACTION_MEDIA_BUTTON);
      mRemoteControlClientReceiver = new RemoteControlClientReceiver();
      registerReceiver(mRemoteControlClientReceiver, filter);
    }

    AudioUtil.prepareCacheFolder(this);
  }