use of android.media.MediaPlayer.OnVideoSizeChangedListener in project SimplifyReader by chentao0707.
the class YoukuBasePlayerActivity method initMediaPlayer.
private void initMediaPlayer() {
//---------->内部使用
// mediaPlayerDelegate.mediaPlayer = BaseMediaPlayer.getInstance();
mediaPlayerDelegate.mediaPlayer = RemoteInterface.baseMediaPlayer;
mediaPlayerDelegate.mediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
if (onPause) {
mp.release();
return;
}
if (pluginManager == null)
return;
pluginManager.onBufferingUpdateListener(percent);
}
});
mediaPlayerDelegate.mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mediaPlayerDelegate != null)
mediaPlayerDelegate.onComplete();
if (mYoukuPlayerView != null)
mYoukuPlayerView.setPlayerBlack();
}
});
mediaPlayerDelegate.mediaPlayer.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Logger.d("PlayFlow", "播放器出现错误 MediaPlayer onError what=" + what + " !!!");
if (mYoukuPlayerView != null)
mYoukuPlayerView.setDebugText("出现错误-->onError:" + what);
disposeAdErrorLoss(what);
if (isAdPlayError(what)) {
Logger.d("PlayFlow", "出现错误:" + what + " 处理结果:跳过广告播放");
return loadingADOverTime();
}
if (mediaPlayerDelegate != null && !mYoukuPlayerView.realVideoStart) {
runOnUiThread(new Runnable() {
public void run() {
detectPlugin();
}
});
}
if (!isSendPlayBreakEvent && MediaPlayerConfiguration.getInstance().trackPlayError() && mYoukuPlayerView.realVideoStart && mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null) {
final String videoUrl = mediaPlayerDelegate.videoInfo.getWeburl();
final TaskSendPlayBreak task = new TaskSendPlayBreak(videoUrl);
task.execute();
isSendPlayBreakEvent = true;
}
if (mYoukuPlayerView.realVideoStart && mediaPlayerDelegate.isLoading)
Track.onPlayLoadingEnd();
onLoadingFailError();
if (pluginManager == null) {
Logger.d("PlayFlow", "onError出现错误:" + what + " pluginManager == null return false");
return false;
}
//Logger.d("PlayFlow", "出现错误:" + what + " 处理结果:去重�?);"
int nowPostition = mediaPlayerDelegate.getCurrentPosition();
if (nowPostition > 0) {
position = nowPostition;
}
// 系统播放器错误特殊处�?
if (what == -38 && !MediaPlayerProxyUtil.isUplayerSupported()) {
what = MPPErrorCode.MEDIA_INFO_PLAY_UNKNOW_ERROR;
}
return pluginManager.onError(what, extra);
}
private boolean isAdPlayError(int what) {
return what == MPPErrorCode.MEDIA_INFO_PREPARED_AD_CHECK || (what == MPPErrorCode.MEDIA_INFO_DATA_SOURCE_ERROR && !mediaPlayerDelegate.isAdvShowFinished()) || (what == MPPErrorCode.MEDIA_INFO_NETWORK_ERROR && mediaPlayerDelegate.isADShowing) || (what == MPPErrorCode.MEDIA_INFO_NETWORK_CHECK && mediaPlayerDelegate.isADShowing);
}
//广告损耗埋点使�?
private void disposeAdErrorLoss(int what) {
if (mediaPlayerDelegate == null || mediaPlayerDelegate.videoInfo == null) {
return;
}
if (what == MPPErrorCode.MEDIA_INFO_DATA_SOURCE_ERROR && !mediaPlayerDelegate.videoInfo.isAdvEmpty()) {
DisposableStatsUtils.disposeAdLoss(YoukuBasePlayerActivity.this, URLContainer.AD_LOSS_STEP4, SessionUnitil.playEvent_session, URLContainer.AD_LOSS_MF);
}
if (what == MPPErrorCode.MEDIA_INFO_PREPARED_AD_CHECK) {
DisposableStatsUtils.disposeAdLoss(YoukuBasePlayerActivity.this, URLContainer.AD_LOSS_STEP6, SessionUnitil.playEvent_session, URLContainer.AD_LOSS_MF);
}
}
});
mediaPlayerDelegate.mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (pluginManager == null)
return;
pluginManager.onPrepared();
}
});
mediaPlayerDelegate.mediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer mp) {
if (mediaPlayerDelegate != null) {
mediaPlayerDelegate.isLoading = false;
}
Track.setTrackPlayLoading(true);
if (pluginManager == null)
return;
runOnUiThread(new Runnable() {
public void run() {
pluginManager.onSeekComplete();
}
});
}
});
mediaPlayerDelegate.mediaPlayer.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
if (pluginManager == null)
return;
pluginManager.onVideoSizeChanged(width, height);
Logger.e(TAG, "onVideoSizeChanged-->" + width + height);
mediaPlayerDelegate.mediaPlayer.updateWidthAndHeight(width, height);
}
});
mediaPlayerDelegate.mediaPlayer.setOnTimeOutListener(new OnTimeoutListener() {
@Override
public void onTimeOut() {
if (mediaPlayerDelegate == null)
return;
Logger.d("PlayFlow", "onTimeOut");
mediaPlayerDelegate.release();
runOnUiThread(new Runnable() {
@Override
public void run() {
Track.pause();
onLoadingFailError();
}
});
if (!isSendPlayBreakEvent && MediaPlayerConfiguration.getInstance().trackPlayError() && mYoukuPlayerView.realVideoStart && mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null) {
final String videoUrl = mediaPlayerDelegate.videoInfo.getWeburl();
final TaskSendPlayBreak task = new TaskSendPlayBreak(videoUrl);
task.execute();
isSendPlayBreakEvent = true;
}
runOnUiThread(new Runnable() {
public void run() {
if (pluginManager == null)
return;
pluginManager.onTimeout();
}
});
}
@Override
public void onNotifyChangeVideoQuality() {
if (pluginManager == null)
return;
Logger.d("PlayFlow", "onNotifyChangeVideoQuality");
pluginManager.onNotifyChangeVideoQuality();
}
});
mediaPlayerDelegate.mediaPlayer.setOnCurrentPositionUpdateListener(new OnCurrentPositionUpdateListener() {
@Override
public void onCurrentPositionUpdate(final int currentPosition) {
if (pluginManager == null)
return;
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
pluginManager.onCurrentPositionChange(currentPosition);
} catch (Exception e) {
}
}
});
}
});
if (PlayerUtil.useUplayer()) {
mediaPlayerDelegate.mediaPlayer.setOnADPlayListener(new OnADPlayListener() {
@Override
public boolean onStartPlayAD(int index) {
Logger.d("PlayFlow", "onstartPlayAD");
Track.onAdStart();
String vid = "";
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null)
vid = mediaPlayerDelegate.videoInfo.getVid();
Track.trackAdLoad(getApplicationContext(), vid);
mYoukuPlayerView.setPlayerBlackGone();
mPluginADPlay.setInteractiveAdVisible(false);
if (mediaPlayerDelegate != null) {
mediaPlayerDelegate.isADShowing = true;
mediaPlayerDelegate.isAdStartSended = true;
if (mediaPlayerDelegate.videoInfo != null && mediaPlayerDelegate.videoInfo.videoAdvInfo != null) {
if (mediaPlayerDelegate.videoInfo.videoAdvInfo.SKIP != null && mediaPlayerDelegate.videoInfo.videoAdvInfo.SKIP.equals("1")) {
if (null != mPluginADPlay) {
mPluginADPlay.setSkipVisible(true);
}
}
if (mediaPlayerDelegate.videoInfo.videoAdvInfo.VAL.get(0).RST.equals("hvideo")) {
if (mPluginADPlay.isInteractiveAdShow()) {
mPluginADPlay.setInteractiveAdVisible(true);
} else {
String brs = mediaPlayerDelegate.videoInfo.videoAdvInfo.VAL.get(0).BRS;
int count = mediaPlayerDelegate.videoInfo.videoAdvInfo.VAL.get(0).AL;
mPluginADPlay.startInteractiveAd(brs, count);
mPluginADPlay.showInteractiveAd();
}
}
}
}
updatePlugin(PLUGIN_SHOW_AD_PLAY);
if (null != pluginManager) {
runOnUiThread(new Runnable() {
public void run() {
pluginManager.onLoaded();
if (null != mPluginADPlay) {
mPluginADPlay.setVisible(true);
}
}
});
}
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null) {
AnalyticsWrapper.adPlayStart(getApplicationContext(), mediaPlayerDelegate.videoInfo);
}
try {
DisposableStatsUtils.disposeSUS(mediaPlayerDelegate.videoInfo);
} catch (NullPointerException e) {
Logger.e("sgh", e.toString());
}
if (mediaPlayerDelegate.videoInfo.getCurrentAdvInfo() != null && (mediaPlayerDelegate.videoInfo.getCurrentAdvInfo().VSC == null || mediaPlayerDelegate.videoInfo.getCurrentAdvInfo().VSC.equalsIgnoreCase(""))) {
DisposableStatsUtils.disposeVC(mediaPlayerDelegate.videoInfo);
}
return false;
}
@Override
public boolean onEndPlayAD(int index) {
Logger.d("PlayFlow", "onEndPlayAD");
if (mediaPlayerDelegate != null) {
mediaPlayerDelegate.isADShowing = false;
}
Track.onAdEnd();
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null) {
AnalyticsWrapper.adPlayEnd(getApplicationContext(), mediaPlayerDelegate.videoInfo);
}
// 必须在removePlayedAdv之前调用
DisposableStatsUtils.disposeSUE(mediaPlayerDelegate.videoInfo);
// 当前广告成功播放完成后,从容器中移除
mediaPlayerDelegate.videoInfo.removePlayedAdv();
if (mediaPlayerDelegate.videoInfo.isCached()) {
ICacheInfo download = IMediaPlayerDelegate.mICacheInfo;
if (download != null) {
if (download.isDownloadFinished(mediaPlayerDelegate.videoInfo.getVid())) {
VideoCacheInfo downloadInfo = download.getDownloadInfo(mediaPlayerDelegate.videoInfo.getVid());
if (YoukuBasePlayerActivity.isHighEnd) {
mediaPlayerDelegate.videoInfo.cachePath = PlayerUtil.getM3u8File(downloadInfo.savePath + "youku.m3u8");
}
}
}
}
if (null != pluginManager) {
runOnUiThread(new Runnable() {
public void run() {
mPluginADPlay.closeInteractiveAdNotIcludeUI();
pluginManager.onLoading();
}
});
}
Logger.e(TAG, "onEndPlayAD");
return false;
}
});
mediaPlayerDelegate.mediaPlayer.setOnADCountListener(new OnADCountListener() {
@Override
public void onCountUpdate(final int count) {
position = mediaPlayerDelegate.getCurrentPosition();
final int currentPosition = mediaPlayerDelegate.getCurrentPosition() / 1000;
runOnUiThread(new Runnable() {
public void run() {
mPluginADPlay.notifyUpdate(count);
mYoukuPlayerView.resizeMediaPlayer(false);
DisposableStatsUtils.disposeSU(mediaPlayerDelegate.videoInfo, currentPosition);
}
});
}
});
mediaPlayerDelegate.mediaPlayer.setOnNetworkSpeedListener(new OnNetworkSpeedListener() {
@Override
public void onSpeedUpdate(final int count) {
if (null != pluginManager) {
runOnUiThread(new Runnable() {
public void run() {
pluginManager.onNetSpeedChange(count);
}
});
}
}
});
}
mediaPlayerDelegate.mediaPlayer.setOnRealVideoStartListener(new OnRealVideoStartListener() {
@Override
public void onRealVideoStart() {
if (onPause)
return;
// 这个listener的理解是正片开始播放的时候调�?这个时候的
// mediaPlayerDelegate为空的概率比较大
Logger.d("PlayFlow", "正片开始播放,没有错误");
Track.isRealVideoStarted = true;
String vid = "";
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null)
vid = mediaPlayerDelegate.videoInfo.getVid();
Track.onRealVideoFirstLoadEnd(getApplicationContext(), vid);
localStartSetDuration();
sentonVVBegin();
mYoukuPlayerView.setPlayerBlackGone();
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null) {
mediaPlayerDelegate.isADShowing = false;
Logger.e(TAG, "onRealVideoStart" + mediaPlayerDelegate.videoInfo.IsSendVV);
} else {
Logger.e(TAG, "onRealVideoStart mediaPlayerDelegate空指");
}
mediaPlayerDelegate.isLoading = false;
if (null != pluginManager) {
runOnUiThread(new Runnable() {
public void run() {
detectPlugin();
pluginManager.onRealVideoStart();
pluginManager.onLoaded();
}
});
}
if (mediaPlayerDelegate != null) {
if (mediaPlayerDelegate.videoInfo != null && mediaPlayerDelegate.videoInfo.getProgress() > 1000 && !mediaPlayerDelegate.videoInfo.isHLS) {
mediaPlayerDelegate.seekTo(mediaPlayerDelegate.videoInfo.getProgress());
Logger.e("PlayFlow", "SEEK TO" + mediaPlayerDelegate.videoInfo.getProgress());
}
}
runOnUiThread(new Runnable() {
public void run() {
if (mInvestigate != null) {
mInvestigate.show();
}
}
});
}
});
mediaPlayerDelegate.mediaPlayer.setOnLoadingStatusListener(new OnLoadingStatusListener() {
@Override
public void onStartLoading() {
Logger.e(TAG, "onStartLoading");
if (pluginManager == null || onPause)
return;
Track.onPlayLoadingStart(mediaPlayerDelegate.mediaPlayer.getCurrentPosition());
if (mediaPlayerDelegate != null) {
mediaPlayerDelegate.isLoading = true;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if (pluginManager == null)
return;
pluginManager.onLoading();
if (PlayerUtil.useUplayer() && !mediaPlayerDelegate.videoInfo.isUseCachePath())
mediaPlayerDelegate.loadingPause();
}
});
}
@Override
public void onEndLoading() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (pluginManager == null)
return;
pluginManager.onLoaded();
}
});
Track.onPlayLoadingEnd();
if (null != mediaPlayerDelegate) {
mediaPlayerDelegate.isStartPlay = true;
mediaPlayerDelegate.isLoading = false;
if (null != mediaPlayerDelegate.videoInfo) {
id = mediaPlayerDelegate.videoInfo.getVid();
mediaPlayerDelegate.videoInfo.isFirstLoaded = true;
}
// 本地mp4不控制自动开�?
if (PlayerUtil.useUplayer() && !mediaPlayerDelegate.videoInfo.isUseCachePath())
mediaPlayerDelegate.start();
}
if (!firstLoaded && !isFromLocal() && !PreferenceUtil.getPreferenceBoolean(YoukuBasePlayerActivity.this, "video_lock", false)) {
if (mediaPlayerDelegate != null && !mediaPlayerDelegate.isFullScreen && mediaPlayerDelegate.videoInfo != null && StaticsUtil.PLAY_TYPE_LOCAL.equals(mediaPlayerDelegate.videoInfo.getPlayType()) || !PlayerUtil.isYoukuTablet(YoukuBasePlayerActivity.this)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
Logger.d("lelouch", "onLoaded setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);");
firstLoaded = true;
}
}
});
mediaPlayerDelegate.mediaPlayer.setOnPlayHeartListener(new OnPlayHeartListener() {
@Override
public void onPlayHeart() {
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null)
Track.trackPlayHeart(getApplicationContext(), mediaPlayerDelegate.videoInfo, mediaPlayerDelegate.isFullScreen);
}
});
mediaPlayerDelegate.mediaPlayer.setOnVideoIndexUpdateListener(new OnVideoIndexUpdateListener() {
@Override
public void onVideoIndexUpdate(int currentIndex, int ip) {
Logger.d("PlayFlow", "onVideoIndexUpdate:" + currentIndex + " " + ip);
if (mediaPlayerDelegate != null && mediaPlayerDelegate.videoInfo != null)
Track.onVideoIndexUpdate(getApplicationContext(), currentIndex, ip, mediaPlayerDelegate.videoInfo.getCurrentQuality());
}
});
mediaPlayerDelegate.mediaPlayer.setOnHwDecodeErrorListener(new OnHwDecodeErrorListener() {
@Override
public void OnHwDecodeError() {
Logger.d("PlayFlow", "OnHwDecodeError");
// DisposableHttpTask task = new DisposableHttpTask(
// URLContainer.getHwErrorUrl());
// task.setRequestMethod(DisposableHttpTask.METHOD_POST);
// task.start();
MediaPlayerConfiguration.getInstance().setUseHardwareDecode(false);
}
});
}
Aggregations