android VideoView的使用例程

android VideoView的使用例程一 xxxvideo java public class RemoteVideo extends Activity private String path private String textUrl private VideoView mVideoView

大家好,我是讯享网,很高兴认识大家。

一、 xxxvideo.java

public class RemoteVideo extends Activity {

private String path = "";

private String textUrl = "";

private VideoView mVideoView;

private static int i = 0;

private int width;

private int heigh;

private Dialog dialog;

private Handler mHandler = new Handler();

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Bundle bundle = this.getIntent().getExtras();

DisplayMetrics dm = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(dm);

width=dm.widthPixels;

heigh=dm.heightPixels;

textUrl = bundle.getString("url");

if(width/heigh>0)

{

setContentView(R.layout.videoview);

path = bundle.getString("widthurl");

Log.i("mp4", "heng"+path);

}

if(width/heigh==0)

{

setContentView(R.layout.view);

path = bundle.getString("heighturl");

Log.i("mp4", "shu"+path);

}

dialog=ProgressDialog.show(this, "视频加载中...", "请您稍候");

mVideoView = (VideoView) findViewById(R.id.surface_view);

mVideoView.setVideoPath(path);

MediaController controller = new MediaController(this);

mVideoView.setMediaController(controller);

mVideoView.requestFocus();

mVideoView.setOnPreparedListener(new OnPreparedListener() {

//@Override

public void onPrepared(MediaPlayer mp) {

mVideoView.setBackgroundColor(Color.argb(0, 0, 255, 0));

dialog.dismiss();

}

});

mVideoView.setOnCompletionListener(new OnCompletionListener() {


讯享网

//@Override

public void onCompletion(MediaPlayer mp) {

Toast.makeText(RemoteVideo.this, "video play finished!", Toast.LENGTH_LONG)

.show();

}

});

controller.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {

return true;

}

});

}

@Override

protected void onResume() {

super.onResume();

mVideoView.seekTo(i);

mVideoView.start();

}

@Override

protected void onStop() {

super.onStop();

mVideoView.pause();

i = mVideoView.getCurrentPosition();

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

finish();

return true;

}

return false;

}

}

说明:

1. VideoView可接收本地和远程的视频源并解码;

2.MediaController为videoview的控制条类;

3.bundle获取intent传过来的视频路径;

二、videoview.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent" android:layout_height="fill_parent"

android:gravity="left" android:orientation="horizontal">

<VideoView android:id="@+id/surface_view"

android:layout_width="176px" android:layout_height="132px"

android:layout_gravity="left" />

<WebView android:id="@+id/web_openonline"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

</LinearLayout>

小讯
上一篇 2025-04-07 20:38
下一篇 2025-04-05 07:09

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/64015.html