Exemplo n.º 1
0
        private void OpenVideo()
        {
            if (Uri == null || SurfaceHolder == null)
            {
                return;
            }
            Intent i = new Intent("com.android.music.musicservicecommand");

            i.PutExtra("command", "pause");
            Context.SendBroadcast(i);
            Release(false);
            try
            {
                Duration = -1;
                CurrentBufferPercentage = 0;
                IjkMediaPlayer ijkMediaPlayer = null;
                if (Uri != null)
                {
                    ijkMediaPlayer = new IjkMediaPlayer();
                    ijkMediaPlayer.SetLogEnabled(false);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.FfpPropvDecoderAvcodec, "analyzemaxduration", 100L);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.FfpPropvDecoderAvcodec, "probesize", 10240L);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.FfpPropvDecoderAvcodec, "flush_packets", 1L);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.IjkLogInfo, "packet-buffering", 0L);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.IjkLogInfo, "framedrop", 1L);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "skip_loop_filter", "48");
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "start-on-prepared", 0);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "http-detect-range-support", 0);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "skip_frame", 0);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "max_cached_duration", 3000);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "infbuf", 1);
                    if (Headers != null && Headers.Count > 0)
                    {
                        foreach (var header in Headers)
                        {
                            ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryFormat, header.Key, header.Value);
                        }
                    }
                }
                MediaPlayer = ijkMediaPlayer;
                if (MediaPlayer == null)
                {
                    return;
                }
                MediaPlayer.SetOnPreparedListener(this);
                MediaPlayer.SetOnVideoSizeChangedListener(this);
                MediaPlayer.SetOnCompletionListener(this);
                MediaPlayer.SetOnErrorListener(this);
                MediaPlayer.SetOnBufferingUpdateListener(this);
                MediaPlayer.SetOnInfoListener(this);
                MediaPlayer.SetOnSeekCompleteListener(this);
                if (Uri != null)
                {
                    MediaPlayer.SetDataSource(Context, Uri);
                }
                MediaPlayer.SetDisplay(SurfaceHolder);
                MediaPlayer.SetScreenOnWhilePlaying(true);
                MediaPlayer.PrepareAsync();
                CurrentState = STATE_PREPARING;
                AttachMediaController();
            }
            catch (IOException ex)
            {
                DebugLog.E(TAG, "Unable to open content: " + Uri, ex);
                CurrentState = STATE_ERROR;
                TargetState  = STATE_ERROR;
                OnErrorListener.OnError(MediaPlayer, (int)MediaError.Unknown, 0);
            }
            catch (IllegalArgumentException ex)
            {
                DebugLog.E(TAG, "Unable to open content: " + Uri, ex);
                CurrentState = STATE_ERROR;
                TargetState  = STATE_ERROR;
                OnErrorListener.OnError(MediaPlayer, (int)MediaError.Unknown, 0);
            }
        }
Exemplo n.º 2
0
        private void OpenVideo()
        {
            if (mUri == null || mSurfaceHolder == null)
            {
                return;
            }
            Intent i = new Intent("com.android.music.musicservicecommand");

            i.PutExtra("command", "pause");
            mContext.SendBroadcast(i);
            Release(false);
            try
            {
                mDuration = -1;
                mCurrentBufferPercentage = 0;
                // mMediaPlayer = new AndroidMediaPlayer();
                IjkMediaPlayer ijkMediaPlayer = null;
                if (mUri != null)
                {
                    ijkMediaPlayer = new IjkMediaPlayer();
                    ijkMediaPlayer.SetLogEnabled(false);
                    ijkMediaPlayer.SetOption(IjkMediaPlayer.OptCategoryCodec, "skip_loop_filter", "48");
                }
                mMediaPlayer = ijkMediaPlayer;
                if (mMediaPlayer == null)
                {
                    return;
                }

                mMediaPlayer.SetOnPreparedListener(this);
                mMediaPlayer.SetOnVideoSizeChangedListener(this);
                mMediaPlayer.SetOnCompletionListener(this);
                mMediaPlayer.SetOnErrorListener(this);
                mMediaPlayer.SetOnBufferingUpdateListener(this);
                mMediaPlayer.SetOnInfoListener(this);
                mMediaPlayer.SetOnSeekCompleteListener(this);//;mOnSeekCompleteListener);

                if (mUri != null)
                {
                    mMediaPlayer.SetDataSource(mContext, mUri);
                }
                mMediaPlayer.SetDisplay(mSurfaceHolder);
                mMediaPlayer.SetScreenOnWhilePlaying(true);
                mMediaPlayer.PrepareAsync();
                mCurrentState = STATE_PREPARING;
                AttachMediaController();
            }
            catch (IOException ex)
            {
                DebugLog.E(TAG, "Unable to open content: " + mUri, ex);
                mCurrentState = STATE_ERROR;
                mTargetState  = STATE_ERROR;
                mOnErrorListener.OnError(mMediaPlayer, (int)MediaError.Unknown, 0);
            }
            catch (IllegalArgumentException ex)
            {
                DebugLog.E(TAG, "Unable to open content: " + mUri, ex);
                mCurrentState = STATE_ERROR;
                mTargetState  = STATE_ERROR;
                mOnErrorListener.OnError(mMediaPlayer, (int)MediaError.Unknown, 0);
            }
        }