本文整理汇总了Java中android.widget.VideoView类的典型用法代码示例。如果您正苦于以下问题:Java VideoView类的具体用法?Java VideoView怎么用?Java VideoView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VideoView类属于android.widget包,在下文中一共展示了VideoView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the video view by id so we can use it.
VideoView myVideo = (VideoView) findViewById(R.id.videoView);
// To set the path to the video. Sample.mp4 is in the "raw" folder.
// You can use http://online.path.to.your.video also.
myVideo.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.sample);
// To create the media controller (play, pause, etc.)
MediaController myController = new MediaController(this);
// To link the media controller to the video view.
myController.setAnchorView(myVideo);
// To link the video view to the media controller.
myVideo.setMediaController(myController);
// To autoplay on opening.
myVideo.start();
}
示例2: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//强制竖屏
final VideoView vv=new VideoView(this.getContext());
RelativeLayout rlmain=new RelativeLayout(this.getContext());
this.setContentView(vv);
TextView txt=new TextView(rlmain.getContext());
rlmain.addView(txt);
txt.setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
// rlmain.setBackgroundColor(Color.RED);
vv.setVideoPath("/sdcard/mwwyt.mpg");
vv.start();
vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
vv.start();
}
});
}
示例3: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView=(VideoView)findViewById(R.id.video_view);
Button play=(Button)findViewById(R.id.play);
Button pause=(Button)findViewById(R.id.pause);
Button replay=(Button)findViewById(R.id.replay);
play.setOnClickListener(this);
pause.setOnClickListener(this);
replay.setOnClickListener(this);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.
WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MainActivity.this,new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
}else {
initVideoPath();//初始化VideoView
}
}
示例4: init
import android.widget.VideoView; //导入依赖的package包/类
private void init(String videoPath) {
setContentView(R.layout.activity_trim);
TextView duration = (TextView) findViewById(R.id.duration);
mPreview = (VideoView) findViewById(R.id.preview);
mShortVideoTrimmer = new PLShortVideoTrimmer(this, videoPath, Config.TRIM_FILE_PATH);
mMediaFile = new PLMediaFile(videoPath);
mSelectedEndMs = mDurationMs = mMediaFile.getDurationMs();
duration.setText("时长: " + formatTime(mDurationMs));
Log.i(TAG, "video duration: " + mDurationMs);
mVideoFrameCount = mMediaFile.getVideoFrameCount(false);
Log.i(TAG, "video frame count: " + mVideoFrameCount);
mPreview.setVideoPath(videoPath);
mPreview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
play();
}
});
initVideoFrameList();
}
示例5: onCreate
import android.widget.VideoView; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected final void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContentView = new VideoView(this);
mContentView.setVisibility(View.GONE);
mContentView.setOnPreparedListener(new OnPreparedListener());
final FrameLayout.LayoutParams layoutParams =
new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER);
mContentView.setLayoutParams(layoutParams);
setContentView(mContentView);
startEncode(new File(getFilesDir(), OUTPUT_FILE_NAME).getAbsolutePath());
}
示例6: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
VideoView videoView = new VideoView(this);
setContentView(videoView);
videoView.setMediaController(new MediaController(this));
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText( VideoPlayerActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
}
});
String videoPath = getIntent().getStringExtra("videoPath");
try {
videoView.setVideoPath(videoPath);
videoView.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(VideoPlayerActivity.this, "视频不存在", Toast.LENGTH_SHORT).show();
}
}
示例7: go
import android.widget.VideoView; //导入依赖的package包/类
private void go() {
VideoView v=(VideoView)findViewById(R.id.videoView) ;
final ProgressBar p=(ProgressBar)findViewById(R.id.progressBar3);
v.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
p.setVisibility(View.GONE);
}
});
String s="https://firebasestorage.googleapis.com/v0/b/lifesaver-18f28.appspot.com/o/flood.mp4?alt=media&token=179d7e4e-7171-4a87-b1f8-b1fc3d976c60";
Uri uri=Uri.parse(s);
v.setVideoURI(uri);
v.setVideoPath(s);
v.requestFocus();
v.start();
}
示例8: go
import android.widget.VideoView; //导入依赖的package包/类
private void go() {
final ProgressBar p=(ProgressBar)findViewById(R.id.progressBar2);
VideoView v=(VideoView)findViewById(R.id.videoView2) ;
v.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
p.setVisibility(View.GONE);
}
});
String s="https://firebasestorage.googleapis.com/v0/b/lifesaver-18f28.appspot.com/o/earthquake.mp4?alt=media&token=98993371-823d-4b81-adc7-d9d87ec841a9";
Uri uri=Uri.parse(s);
v.setVideoURI(uri);
v.setVisibility(View.VISIBLE);
v.setVideoPath(s);
v.requestFocus();
v.start();
}
示例9: initPlayer
import android.widget.VideoView; //导入依赖的package包/类
public static void initPlayer(VideoView videoView, OnPreparedListener onPreparedListener,
OnCompletionListener onCompletionListener, OnErrorListener
onErrorListener) {
if (onPreparedListener != null) {
videoView.setOnPreparedListener(onPreparedListener);
}
if (onCompletionListener != null) {
videoView.setOnCompletionListener(onCompletionListener);
}
if (onErrorListener != null) {
videoView.setOnErrorListener(onErrorListener);
}
}
示例10: inject
import android.widget.VideoView; //导入依赖的package包/类
public void inject(Finder finder, final T target, Object source) {
target.progressBar = (ProgressWheel) finder.castView((View) finder.findRequiredView
(source, R.id.progress_bar, "field 'progressBar'"), R.id.progress_bar, "field " +
"'progressBar'");
target.progressLayout = (RelativeLayout) finder.castView((View) finder.findRequiredView
(source, R.id.progress_layout, "field 'progressLayout'"), R.id.progress_layout,
"field 'progressLayout'");
View view = (View) finder.findRequiredView(source, R.id.btn_close, "field 'btnClose' and " +
"method 'onClick'");
target.btnClose = (ImageView) finder.castView(view, R.id.btn_close, "field 'btnClose'");
view.setOnClickListener(new DebouncingOnClickListener() {
public void doClick(View p0) {
target.onClick(p0);
}
});
target.videoView = (VideoView) finder.castView((View) finder.findRequiredView(source, R
.id.video_view, "field 'videoView'"), R.id.video_view, "field 'videoView'");
target.viewPager = (ViewPager) finder.castView((View) finder.findRequiredView(source, R
.id.view_pager, "field 'viewPager'"), R.id.view_pager, "field 'viewPager'");
target.tvIndex = (TextView) finder.castView((View) finder.findRequiredView(source, R.id
.tv_index, "field 'tvIndex'"), R.id.tv_index, "field 'tvIndex'");
}
示例11: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = getIntent().getExtras().getString(Constants.URL);
setContentView(R.layout.fragment_video_gallery);
final VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
View progress = findViewById(R.id.videoProgress);
progress.setVisibility(View.GONE);
videoView.requestFocus();
MediaController vidControl = new MediaController(VideoPlayerActivity.this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.start();
}
});
videoView.setVideoURI(Uri.parse(url));
}
示例12: loadViews
import android.widget.VideoView; //导入依赖的package包/类
private void loadViews() {
mVideoView = (VideoView) findViewById(R.id.videoView1);
mTitleView = (TextView) findViewById(R.id.titleTextView);
mDescriptionView = (TextView) findViewById(R.id.descriptionTextView);
mDescriptionView.setMovementMethod(new ScrollingMovementMethod());
mAuthorView = (TextView) findViewById(R.id.authorTextView);
mStartText = (TextView) findViewById(R.id.startText);
mStartText.setText(Utils.formatMillis(0));
mEndText = (TextView) findViewById(R.id.endText);
mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
mPlayPause = (ImageView) findViewById(R.id.playPauseImageView);
mLoading = (ProgressBar) findViewById(R.id.progressBar1);
mControllers = findViewById(R.id.controllers);
mContainer = findViewById(R.id.container);
mCoverArt = (ImageView) findViewById(R.id.coverArtView);
ViewCompat.setTransitionName(mCoverArt, getString(R.string.transition_image));
mPlayCircle = (ImageButton) findViewById(R.id.play_circle);
mPlayCircle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
togglePlayback();
}
});
}
示例13: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
mVideoPath = getIntent().getStringExtra("videoPath");
if (!TextUtils.isEmpty(mVideoPath)) {
new RecentMediaStorage(this).saveUrlAsync(mVideoPath);
}
videoView = (VideoView) findViewById(R.id.view_video);
android.widget.MediaController mediaController = new android.widget.MediaController(this);
videoView.setMediaController(mediaController);
videoView.setVideoPath(mVideoPath);
videoView.start();
}
示例14: onCreate
import android.widget.VideoView; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_play);
enableLayoutFullScreen();
mVideoView = (VideoView) findViewById(R.id.video_view);
playView = (ImageView) findViewById(R.id.play_view);
playView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playView.setVisibility(View.GONE);
mVideoView.start();
}
});
String videoPath = getIntent().getStringExtra(KEY_VIDEO_PATH);
mVideoView.setVideoPath(videoPath);
mVideoView.start();
mVideoView.setOnCompletionListener(this);
}
示例15: init
import android.widget.VideoView; //导入依赖的package包/类
private void init() {
ivPlay = (ImageView) findViewById(R.id.previre_play);
btDelete = (Button) findViewById(R.id.bt_cancel);
ivImage = (ImageView) findViewById(R.id.iv_image);
vvContent = (VideoView) findViewById(R.id.vv_content);
ivPlay.setOnClickListener(this);
btDelete.setOnClickListener(this);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options);
ivImage.setImageBitmap(bitmap);
if (videoPath.equals("")) {
ivPlay.setVisibility(View.GONE);
vvContent.setVisibility(View.GONE);
}
}