android 随手记 videoview循环播放网络视频 和mediaplayer+sufaceview播放网络视频
1:videoview循环播放视频 1》xml
[html]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<VideoView
android:id="@+id/vv_player"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
2》java代码
[html]
package com.example.testhour;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.Su易做图ceView;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
private VideoView videoview;
private MediaController mMediaController;
private String url1 = "http://g3.letv.cn/24/6/3/letv-uts/2522145-AVC-1611234-AAC-122967-2076960-463162247-274c0504575322ddd3fbc512818de8ae-1366891476558.flv";
private String url2 = "http://g3.letv.cn/27/9/3/letv-uts/2522159-AVC-1610564-AAC-123276-2196960-489820604-1b165c6eec261a12e925f48f7ca35892-1366904195636.flv";
private String url = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
private Su易做图ceView su易做图ceview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
initview();
loadView2(url);
}
private void initview() {
videoview = (VideoView) findViewById(R.id.vv_player);
// mMediaController = new MediaController(this);
// videoview.setMediaController(mMediaController);
}
public void loadView2(String path) {
Uri uri = Uri.parse(path);
videoview.setVideoURI(uri);
videoview.start();
videoview.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();// 播放
mp.setLooping(true);
}
});
videoview.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
android.util.Log.i("test", "播放完毕");
Uri uri = Uri.parse(url);
videoview.setVideoURI(uri);
videoview.start();// 播放
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private Handler mHandler = new Handler() {
@SuppressLint("NewApi")
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 33:
loadView2(url2);
break;
}
};
};
}
2,mediaplayer+sufaceview播放视频
1》xml
[html]
<?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:orientation="vertical" >
<Su易做图ceView
android:id="@+id/su易做图ceView"
android:layout_width="fill_parent"
android:layout_height="500px"
补充:移动开发 , Android ,