|
| 1 | +/* |
| 2 | + * Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package tv.danmaku.ijk.media.player; |
| 18 | + |
| 19 | +public abstract class AbstractMediaPlayer implements IMediaPlayer { |
| 20 | + private OnPreparedListener mOnPreparedListener; |
| 21 | + private OnCompletionListener mOnCompletionListener; |
| 22 | + private OnBufferingUpdateListener mOnBufferingUpdateListener; |
| 23 | + private OnSeekCompleteListener mOnSeekCompleteListener; |
| 24 | + private OnVideoSizeChangedListener mOnVideoSizeChangedListener; |
| 25 | + private OnErrorListener mOnErrorListener; |
| 26 | + private OnInfoListener mOnInfoListener; |
| 27 | + |
| 28 | + public final void setOnPreparedListener(OnPreparedListener listener) { |
| 29 | + mOnPreparedListener = listener; |
| 30 | + } |
| 31 | + |
| 32 | + public final void setOnCompletionListener(OnCompletionListener listener) { |
| 33 | + mOnCompletionListener = listener; |
| 34 | + } |
| 35 | + |
| 36 | + public final void setOnBufferingUpdateListener( |
| 37 | + OnBufferingUpdateListener listener) { |
| 38 | + mOnBufferingUpdateListener = listener; |
| 39 | + } |
| 40 | + |
| 41 | + public final void setOnSeekCompleteListener(OnSeekCompleteListener listener) { |
| 42 | + mOnSeekCompleteListener = listener; |
| 43 | + } |
| 44 | + |
| 45 | + public final void setOnVideoSizeChangedListener( |
| 46 | + OnVideoSizeChangedListener listener) { |
| 47 | + mOnVideoSizeChangedListener = listener; |
| 48 | + } |
| 49 | + |
| 50 | + public final void setOnErrorListener(OnErrorListener listener) { |
| 51 | + mOnErrorListener = listener; |
| 52 | + } |
| 53 | + |
| 54 | + public final void setOnInfoListener(OnInfoListener listener) { |
| 55 | + mOnInfoListener = listener; |
| 56 | + } |
| 57 | + |
| 58 | + public void resetListeners() { |
| 59 | + mOnPreparedListener = null; |
| 60 | + mOnBufferingUpdateListener = null; |
| 61 | + mOnCompletionListener = null; |
| 62 | + mOnSeekCompleteListener = null; |
| 63 | + mOnVideoSizeChangedListener = null; |
| 64 | + mOnErrorListener = null; |
| 65 | + mOnInfoListener = null; |
| 66 | + } |
| 67 | + |
| 68 | + protected final void notifyOnPrepared() { |
| 69 | + if (mOnPreparedListener != null) |
| 70 | + mOnPreparedListener.onPrepared(this); |
| 71 | + } |
| 72 | + |
| 73 | + protected final void notifyOnCompletion() { |
| 74 | + if (mOnCompletionListener != null) |
| 75 | + mOnCompletionListener.onCompletion(this); |
| 76 | + } |
| 77 | + |
| 78 | + protected final void notifyOnBufferingUpdate(int percent) { |
| 79 | + if (mOnBufferingUpdateListener != null) |
| 80 | + mOnBufferingUpdateListener.onBufferingUpdate(this, percent); |
| 81 | + } |
| 82 | + |
| 83 | + protected final void notifyOnSeekComplete() { |
| 84 | + if (mOnSeekCompleteListener != null) |
| 85 | + mOnSeekCompleteListener.onSeekComplete(this); |
| 86 | + } |
| 87 | + |
| 88 | + protected final void notifyOnVideoSizeChanged(int width, int height, |
| 89 | + int sarNum, int sarDen) { |
| 90 | + if (mOnVideoSizeChangedListener != null) |
| 91 | + mOnVideoSizeChangedListener.onVideoSizeChanged(this, width, height, |
| 92 | + sarNum, sarDen); |
| 93 | + } |
| 94 | + |
| 95 | + protected final boolean notifyOnError(int what, int extra) { |
| 96 | + if (mOnErrorListener != null) |
| 97 | + return mOnErrorListener.onError(this, what, extra); |
| 98 | + return false; |
| 99 | + } |
| 100 | + |
| 101 | + protected final boolean notifyOnInfo(int what, int extra) { |
| 102 | + if (mOnInfoListener != null) |
| 103 | + return mOnInfoListener.onInfo(this, what, extra); |
| 104 | + return false; |
| 105 | + } |
| 106 | +} |
0 commit comments