Esempio n. 1
0
 @Override
 public void handleMessage(Message msg) {
   Log.v(TAG, Logging.getCurrentMethodName(msg));
   int event = msg.getData().getInt("event");
   if (event == EventManager.MediaPlayerPlaying) {
     Log.i(TAG, "connected to the stream " + mCurrentPath);
     Log.i(TAG, "latest command: " + mLatestCommand);
     // checking, since this event might also come when resuming
     if (mLatestCommand == FromLogicToPlayer.PLAY) {
       mEventsProcessor.onConnectedToStream();
     }
     mErrorsCounter = 0;
   } else if (event == EventManager.MediaPlayerEndReached) {
     Log.i(TAG, "media player end reached, reporting completion");
     mEventsProcessor.onCompletion();
   } else if (event == EventManager.MediaPlayerEncounteredError) {
     // occurs when trying to connect to a stream that is not ready
     mErrorsCounter++;
     Log.i(TAG, "media player error number " + mErrorsCounter);
     if (mErrorsCounter > PlayerConsts.RETRIES_LIMIT) {
       Log.i(TAG, "error number has exceeded the limit, reporting to player logic");
       mEventsProcessor.onError();
       mErrorsCounter = 0;
     } else {
       Log.i(TAG, "media player error number is still below the limit, retrying");
       mExecutor.execute(
           new ReadMediaTask(
               mLibVlcInstance, mCurrentPath, PlayerConsts.SLEEP_BEFORE_RETRY_MILLIS));
     }
   }
 }
Esempio n. 2
0
 public static VlcMediaPlayer getInstance(PlayerEventProcessor processor) {
   Log.v(TAG, Logging.getCurrentMethodName(processor));
   synchronized (VlcMediaPlayer.class) {
     if (mInstance == null) {
       mInstance = new VlcMediaPlayer(processor);
     }
     return mInstance;
   }
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 public void onResumePlayback() {
   Log.v(TAG, Logging.getCurrentMethodName());
   mLatestCommand = FromLogicToPlayer.RESUME;
   mLibVlcInstance.play();
 }
Esempio n. 5
0
 public void onPausePlayback() {
   Log.v(TAG, Logging.getCurrentMethodName());
   mLatestCommand = FromLogicToPlayer.PAUSE;
   mLibVlcInstance.pause();
 }
Esempio n. 6
0
 /**
  * Starts asynchronously attempting to open the path. If it cannot be opened in {@link
  * PlayerConsts.RETRIES_LIMIT} attempts, an error is reported to the PlayerEventProcessor (the
  * onError() call). If the path has been opened successfully, then PlayerEventProcessor's
  * onConnectedToStream() is called.
  *
  * @param path url to a media stream or a file
  */
 public void onStartPlayback(String path) {
   Log.v(TAG, Logging.getCurrentMethodName(path));
   mCurrentPath = path;
   mLatestCommand = FromLogicToPlayer.PLAY;
   mExecutor.execute(new ReadMediaTask(mLibVlcInstance, mCurrentPath));
 }
Esempio n. 7
0
 /**
  * @return an instance or <code>null</code> if {@link #getInstance(PlayerEventProcessor
  *     processor)} has not been called beforehand.
  */
 public static VlcMediaPlayer getExistingInstance() {
   Log.v(TAG, Logging.getCurrentMethodName());
   synchronized (VlcMediaPlayer.class) {
     return mInstance;
   }
 }
Esempio n. 8
0
 public void detachSurface() {
   Log.v(TAG, Logging.getCurrentMethodName());
   mLibVlcInstance.detachSurface();
 }
Esempio n. 9
0
 /**
  * Played video will be rendered to the provided surface
  *
  * @param surface
  * @param scaleCallback
  * @param width
  * @param height
  */
 public void attachSurface(
     Surface surface, SurfaceScaleCallback scaleCallback, int width, int height) {
   Log.v(TAG, Logging.getCurrentMethodName());
   mLibVlcInstance.attachSurface(surface, scaleCallback, width, height);
 }
Esempio n. 10
0
 public void onStopPlayback() {
   Log.v(TAG, Logging.getCurrentMethodName());
   mLatestCommand = FromLogicToPlayer.STOP;
   mLibVlcInstance.stop();
 }