Beispiel #1
0
 public bool OnError(IMediaPlayer p0, int what, int extra)
 {
     DebugLog.Dfmt(TAG, "Error: %d, %d", what, extra);
     CurrentState = STATE_ERROR;
     TargetState  = STATE_ERROR;
     if (MediaController != null)
     {
         MediaController.Hide();
     }
     if (OnErrorListener != null)
     {
         if (OnErrorListener.OnError(MediaPlayer, what, extra))
         {
             return(true);
         }
     }
     if (WindowToken != null)
     {
         int message = what == (int)MediaError.NotValidForProgressivePlayback ?
                       Resource.String.video_error_text_invalid_progressive_playback : Resource.String.video_error_text_unknown;
         new AlertDialog.Builder(Context)
         .SetTitle(Resource.String.video_error_title)
         .SetMessage(message)
         .SetPositiveButton(Resource.String.video_error_button, (dialog, whichButton) =>
         {
             if (OnCompletionListener != null)
             {
                 OnCompletionListener.OnCompletion(MediaPlayer);
             }
         }).SetCancelable(false).Show();
     }
     return(true);
 }
Beispiel #2
0
 public bool OnInfo(IMediaPlayer mp, int what, int extra)
 {
     DebugLog.Dfmt(TAG, "onInfo: (%d, %d)", what, extra);
     if (OnInfoListener != null)
     {
         OnInfoListener.OnInfo(mp, what, extra);
     }
     else if (MediaPlayer != null)
     {
         if (what == (int)global::Android.Media.MediaInfo.BufferingStart)
         {
             DebugLog.Dfmt(TAG, "onInfo: (MEDIA_INFO_BUFFERING_START)");
             if (MediaBufferingIndicator != null)
             {
                 MediaBufferingIndicator.Visibility = ViewStates.Visible;
             }
         }
         else if (what == (int)global::Android.Media.MediaInfo.BufferingEnd)
         {
             DebugLog.Dfmt(TAG, "onInfo: (MEDIA_INFO_BUFFERING_END)");
             if (MediaBufferingIndicator != null)
             {
                 MediaBufferingIndicator.Visibility = ViewStates.Gone;
             }
         }
     }
     return(true);
 }
Beispiel #3
0
 public void OnVideoSizeChanged(IMediaPlayer mp, int width, int height, int sarNum, int sarDen)
 {
     DebugLog.Dfmt(TAG, "onVideoSizeChanged: (%dx%d)", width, height);
     VideoWidth  = mp.VideoWidth;
     VideoHeight = mp.VideoHeight;
     VideoSarNum = sarNum;
     VideoSarDen = sarDen;
     if (VideoWidth != 0 && VideoHeight != 0)
     {
         SetVideoLayout(VideoLayout);
     }
 }
Beispiel #4
0
 public void OnVideoSizeChanged(IMediaPlayer mp, int width, int height, int sarNum, int sarDen)
 {
     DebugLog.Dfmt(TAG, "onVideoSizeChanged: (%dx%d)", width, height);
     //Log.Info(TAG, "onVideoSizeChanged: (%dx%d)", width, height);
     mVideoWidth  = mp.VideoWidth;  //. GetVideoWidth();
     mVideoHeight = mp.VideoHeight; // getVideoHeight();
     mVideoSarNum = sarNum;
     mVideoSarDen = sarDen;
     if (mVideoWidth != 0 && mVideoHeight != 0)
     {
         SetVideoLayout(mVideoLayout);
     }
 }
Beispiel #5
0
        public void OnPrepared(IMediaPlayer mp)
        {
            DebugLog.Dfmt(TAG, "OnPrepared");
            mCurrentState = STATE_PREPARED;
            mTargetState  = STATE_PLAYING;
            if (mOnPreparedListener != null)
            {
                mOnPreparedListener.OnPrepared(mMediaPlayer);
            }
            if (mMediaController != null)
            {
                mMediaController.SetEnabled(true); // .Enabled = true;// setEnabled(true);
            }
            mVideoWidth  = mp.VideoWidth;          // getVideoWidth();
            mVideoHeight = mp.VideoHeight;         // getVideoHeight();
            long seekToPosition = mSeekWhenPrepared;

            if (seekToPosition != 0)
            {
                SeekTo(seekToPosition);
            }
            if (mVideoWidth != 0 && mVideoHeight != 0)
            {
                SetVideoLayout(mVideoLayout);
                if (mSurfaceWidth == mVideoWidth &&
                    mSurfaceHeight == mVideoHeight)
                {
                    if (mTargetState == STATE_PLAYING)
                    {
                        Start();
                        if (mMediaController != null)
                        {
                            mMediaController.Show();
                        }
                    }
                    else if (!IsPlaying() &&
                             (seekToPosition != 0 || GetCurrentPosition() > 0))
                    {
                        if (mMediaController != null)
                        {
                            mMediaController.Show(0);
                        }
                    }
                }
            }
            else if (mTargetState == STATE_PLAYING)
            {
                Start();
            }
        }
Beispiel #6
0
        public void SetVideoLayout(int layout)
        {
            //LinearLayout linelayout = FindViewById<LinearLayout>(layout);// new LinearLayout(mContext);
            LayoutParams lp = base.LayoutParameters;// linelayout.LayoutParameters;// FindViewById<LayoutParams>(layout);// GetChildAt(0). new LayoutParams(mContext, mAttr);// v.LayoutParameters;//  GetLayoutParams();
            var          res = ScreenResolution.GetResolution(mContext);
            int          windowWidth = res.FirstOrDefault().Key, windowHeight = res.FirstOrDefault().Value;
            float        windowRatio = windowWidth / (float)windowHeight;
            int          sarNum      = mVideoSarNum;
            int          sarDen      = mVideoSarDen;

            if (mVideoHeight > 0 && mVideoWidth > 0)
            {
                float videoRatio = ((float)(mVideoWidth)) / mVideoHeight;
                if (sarNum > 0 && sarDen > 0)
                {
                    videoRatio = videoRatio * sarNum / sarDen;
                }
                mSurfaceHeight = mVideoHeight;
                mSurfaceWidth  = mVideoWidth;
                if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth &&
                    mSurfaceHeight < windowHeight)
                {
                    lp.Width  = (int)(mSurfaceHeight * videoRatio);
                    lp.Height = mSurfaceHeight;
                }
                else if (layout == VIDEO_LAYOUT_ZOOM)
                {
                    lp.Width = windowRatio > videoRatio ? windowWidth
                            : (int)(videoRatio * windowHeight);
                    lp.Height = windowRatio < videoRatio ? windowHeight
                            : (int)(windowWidth / videoRatio);
                }
                else
                {
                    bool full = layout == VIDEO_LAYOUT_STRETCH;
                    lp.Width = (full || windowRatio < videoRatio) ? windowWidth
                            : (int)(videoRatio * windowHeight);
                    lp.Height = (full || windowRatio > videoRatio) ? windowHeight
                            : (int)(windowWidth / videoRatio);
                }
                Holder.SetFixedSize(mSurfaceWidth, mSurfaceHeight);
                DebugLog.Dfmt(
                    TAG,
                    "VIDEO: %dx%dx%f[SAR:%d:%d], Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f",
                    mVideoWidth, mVideoHeight, videoRatio, mVideoSarNum,
                    mVideoSarDen, mSurfaceWidth, mSurfaceHeight, lp.Width,
                    lp.Height, windowWidth, windowHeight, windowRatio);
            }
            mVideoLayout = layout;
        }
Beispiel #7
0
 public void OnPrepared(IMediaPlayer mp)
 {
     DebugLog.Dfmt(TAG, "OnPrepared");
     CurrentState = STATE_PREPARED;
     TargetState  = STATE_PLAYING;
     if (OnPreparedListener != null)
     {
         OnPreparedListener.OnPrepared(MediaPlayer);
     }
     if (MediaController != null)
     {
         MediaController.SetEnabled(true);
     }
     VideoWidth  = mp.VideoWidth;
     VideoHeight = mp.VideoHeight;
     if (SeekWhenPrepared != 0)
     {
         SeekTo(SeekWhenPrepared);
     }
     if (VideoWidth != 0 && VideoHeight != 0)
     {
         SetVideoLayout(VideoLayout);
         if (SurfaceWidth == VideoWidth && SurfaceHeight == VideoHeight)
         {
             if (TargetState == STATE_PLAYING)
             {
                 Start();
                 if (MediaController != null)
                 {
                     MediaController.Show();
                 }
             }
             else if (!IsPlaying() && (SeekWhenPrepared != 0 || GetCurrentPosition() > 0))
             {
                 if (MediaController != null)
                 {
                     MediaController.Show(0);
                 }
             }
         }
     }
     else if (TargetState == STATE_PLAYING)
     {
         Start();
     }
 }
Beispiel #8
0
        public void SetVideoLayout(int layout)
        {
            LayoutParams lp = base.LayoutParameters;
            var          res = ScreenResolution.GetResolution(Context);
            int          windowWidth = res.FirstOrDefault().Key, windowHeight = res.FirstOrDefault().Value;
            float        windowRatio = windowWidth / (float)windowHeight;
            int          sarNum      = VideoSarNum;
            int          sarDen      = VideoSarDen;

            if (VideoHeight > 0 && VideoWidth > 0)
            {
                float videoRatio = ((float)(VideoWidth)) / VideoHeight;
                if (sarNum > 0 && sarDen > 0)
                {
                    videoRatio = videoRatio * sarNum / sarDen;
                }
                SurfaceHeight = VideoHeight;
                SurfaceWidth  = VideoWidth;
                if (VIDEO_LAYOUT_ORIGIN == layout && SurfaceWidth < windowWidth && SurfaceHeight < windowHeight)
                {
                    lp.Width  = (int)(SurfaceHeight * videoRatio);
                    lp.Height = SurfaceHeight;
                }
                else if (layout == VIDEO_LAYOUT_ZOOM)
                {
                    lp.Width  = windowRatio > videoRatio ? windowWidth : (int)(videoRatio * windowHeight);
                    lp.Height = windowRatio < videoRatio ? windowHeight : (int)(windowWidth / videoRatio);
                }
                else
                {
                    bool full = layout == VIDEO_LAYOUT_STRETCH;
                    lp.Width  = (full || windowRatio < videoRatio) ? windowWidth : (int)(videoRatio * windowHeight);
                    lp.Height = (full || windowRatio > videoRatio) ? windowHeight : (int)(windowWidth / videoRatio);
                }
                Holder.SetFixedSize(SurfaceWidth, SurfaceHeight);
                DebugLog.Dfmt(TAG,
                              "VIDEO: %dx%dx%f[SAR:%d:%d], Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f",
                              VideoWidth, VideoHeight, videoRatio, VideoSarNum,
                              VideoSarDen, SurfaceWidth, SurfaceHeight, lp.Width,
                              lp.Height, windowWidth, windowHeight, windowRatio);
            }
            VideoLayout = layout;
        }