本文整理汇总了Java中io.vov.vitamio.MediaPlayer类的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer类的具体用法?Java MediaPlayer怎么用?Java MediaPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaPlayer类属于io.vov.vitamio包,在下文中一共展示了MediaPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadVideo
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
protected void loadVideo(String name,String url){
Uri uri = Uri.parse(url);
tv_live_nickname.setText(name);
mVideoView.setVideoURI(uri);
mVideoView.setBufferSize(1024 * 1024 * 2);
/*
* 设置视频质量。参数quality参见MediaPlayer的常量:
* VIDEOQUALITY_LOW(流畅)、VIDEOQUALITY_MEDIUM(普通)、VIDEOQUALITY_HIGH(高质)。
*/
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
layout_ll_loading.setVisibility(View.GONE);
iv_live_play.setImageResource(R.drawable.jc_click_pause_selector);
mHandler.sendEmptyMessageDelayed(HIDE_TOP_BOTTOM_BAR, HIDE_TOP_BOTTOM_TIME);
}
});
}
示例2: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaController != null)
mMediaController.hide();
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());
new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例3: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaController != null)
mMediaController.hide();
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()) : getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());
new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例4: onInfo
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
Log.d("onInfo: (%d, %d)", what, extra);
if (mOnInfoListener != null) {
mOnInfoListener.onInfo(mp, what, extra);
} else if (mMediaPlayer != null) {
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
mMediaPlayer.pause();
if (mMediaBufferingIndicator != null)
mMediaBufferingIndicator.setVisibility(View.VISIBLE);
} else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
mMediaPlayer.start();
if (mMediaBufferingIndicator != null)
mMediaBufferingIndicator.setVisibility(View.GONE);
}
}
return true;
}
示例5: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaController != null)
mMediaController.hide();
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());
new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例6: onInfo
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer arg0, int arg1, int arg2) {
switch (arg1) {
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
//开始缓存,暂停播放
if (isPlaying()) {
stopPlayer();
needResume = true;
}
mLoadingView.setVisibility(View.VISIBLE);
break;
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
//缓存完成,继续播放
if (needResume)
startPlayer();
mLoadingView.setVisibility(View.GONE);
break;
case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED:
//显示 下载速度
Logger.e("download rate:" + arg2);
//mListener.onDownloadRateChanged(arg2);
break;
}
return true;
}
示例7: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaController != null)
mMediaController.hide();
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? R.string.video_view_error_text_invalid_progressive_playback : R.string.video_view_error_text_unknown;
new AlertDialog.Builder(mContext).setTitle(R.string.video_view_error_title).setMessage(message).setPositiveButton(R.string.video_view_error_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例8: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()) : getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());
new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例9: onPrepared
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
mVideoDuration = (int)mp.getDuration();
mMediaPlayerValid = true;
mp.setPlaybackSpeed(1.0f);
WritableMap event = Arguments.createMap();
event.putDouble(EVENT_PROP_DURATION, mVideoDuration / 1000.0);
event.putDouble(EVENT_PROP_CURRENT_TIME, mp.getCurrentPosition() / 1000.0);
// TODO: Actually check if you can.
event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
event.putBoolean(EVENT_PROP_SLOW_FORWARD, true);
event.putBoolean(EVENT_PROP_SLOW_REVERSE, true);
event.putBoolean(EVENT_PROP_REVERSE, true);
event.putBoolean(EVENT_PROP_FAST_FORWARD, true);
event.putBoolean(EVENT_PROP_STEP_BACKWARD, true);
event.putBoolean(EVENT_PROP_STEP_FORWARD, true);
mEventEmitter.receiveEvent(getId(), Events.EVENT_LOAD.toString(), event);
applyModifiers();
}
示例10: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
Log.d("Error: %d, %d", framework_err, impl_err);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mOnErrorListener != null) {
if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
return true;
}
if (getWindowToken() != null) {
int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());
new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if (mOnCompletionListener != null)
mOnCompletionListener.onCompletion(mMediaPlayer);
}
}).setCancelable(false).show();
}
return true;
}
示例11: onInfo
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
switch (what) {
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
if (mVideoView.isPlaying()) {
mVideoView.pause();
}
iv_live_play.setImageResource(R.drawable.jc_click_play_selector);
mHandler.removeMessages(HIDE_TOP_BOTTOM_BAR);
showTopBottomBar();
break;
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
layout_ll_loading.setVisibility(View.GONE);
if (!mVideoView.isPlaying()) {
mVideoView.start();
}
iv_live_play.setImageResource(R.drawable.jc_click_pause_selector);
mHandler.sendEmptyMessageDelayed(HIDE_TOP_BOTTOM_BAR, HIDE_TOP_BOTTOM_TIME);
break;
case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED:
// tv_net_info.setText(extra + " kb/s");
break;
default:
break;
}
return true;
}
示例12: onBufferingUpdate
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
layout_ll_loading.setVisibility(View.VISIBLE);
if (mVideoView.isPlaying()) {
mVideoView.pause();
}
tv_loading_buffer.setText("视频已缓冲" + percent + "%...");
}
示例13: onError
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
// svProgressHUD.showErrorWithStatus("主播还在赶来的路上~~");
}
return true;
}
示例14: onCompletion
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
@Override
public void onCompletion(MediaPlayer mp) {
if (mVideoView != null) {
// 释放资源
mVideoView.stopPlayback();
}
}
示例15: onVideoSizeChanged
import io.vov.vitamio.MediaPlayer; //导入依赖的package包/类
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.d("onVideoSizeChanged: (%dx%d)", width, height);
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
mVideoAspectRatio = mp.getVideoAspectRatio();
if (mVideoWidth != 0 && mVideoHeight != 0) {
setVideoLayout(mVideoLayout, mAspectRatio);
}
}