internal LocalPlayer(PlayerController controller, Uri content, Uri subtitlesUri, SurfaceView videoView) { mController = controller; // Create and initialize Android MediaPlayer instance. mPlayer = new MediaPlayer(); mPlayer.OnCompletionListener = this; mSurfaceHolder = videoView.Holder; mSurfaceHolder.addCallback(this); bool isSurfaceValid = mSurfaceHolder.Surface.Valid; if (isSurfaceValid) { mPlayer.Display = mSurfaceHolder; } try { mPlayer.setDataSource(controller.mContext, content); mPlayer.prepare(); if (subtitlesUri != null) { mPlayer.addTimedTextSource(subtitlesUri.Path, MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP); mPlayer.OnTimedTextListener = this; } controller.Duration = mPlayer.Duration / 1000; } catch (IOException ignored) { Log.e("VideoPlayer", ignored.Message); } }
internal LocalPlayer(PlayerController controller, Uri content, Uri subtitlesUri, SurfaceView videoView) { mController = controller; // Create and initialize Android MediaPlayer instance. mPlayer = new MediaPlayer(); mPlayer.OnCompletionListener = this; mSurfaceHolder = videoView.Holder; mSurfaceHolder.addCallback(this); bool isSurfaceValid = mSurfaceHolder.Surface.Valid; if (isSurfaceValid) { mPlayer.Display = mSurfaceHolder; } try { mPlayer.setDataSource(controller.mContext, content); mPlayer.prepare(); if (subtitlesUri != null) { mPlayer.addTimedTextSource(subtitlesUri.Path, MediaPlayer.MEDIA_MIMETYPE_TEXT_SUBRIP); mPlayer.OnTimedTextListener = this; } controller.Duration = mPlayer.Duration / 1000; } catch (IOException ignored) { Log.e("VideoPlayer", ignored.Message); } }
internal LocalPlayer(PlayerController controller, Uri content) { this.mController = controller; // Create and initialize Android MediaPlayer instance. mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(controller.mContext, content); mPlayer.prepare(); controller.Duration = mPlayer.Duration / 1000; } catch (IOException) { // Ignored for application brevity } }
internal LocalPlayer(PlayerController controller, Uri content) { this.mController = controller; // Create and initialize Android MediaPlayer instance. mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(controller.mContext, content); mPlayer.prepare(); controller.Duration = mPlayer.Duration / 1000; } catch (IOException) { // Ignored for application brevity } }
public virtual void stop() { try { mPlayer.stop(); mPlayer.prepare(); // Contrary to documentation, MediaPlayer does not reset position after hide & prepare. mPlayer.seekTo(0); mController.notifyCurrentPosition(0); } catch (System.InvalidOperationException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } mController.CurentState = PlayerState.STOPPED; }