无法使用 Android VideoView 播放 MP4
not able to play MP4 using Android VideoView
我想在 Dialog
框中播放视频以响应 ListView
itemclicked 事件。 Dialog
打开,我收到以下消息:
Can't play this video
代码如下:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
final Dialog dialog = new Dialog(aikiorder.this);
dialog.setContentView(R.layout.aikiitemsample);
dialog.setTitle(aikiNames[position]);
Button b = (Button) dialog.findViewById(R.id.button2);
b.setText(getString(R.string.closeVideoText) + " - " + aikiNames[position]);
dialog.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
final VideoView vv = (VideoView) dialog.findViewById(R.id.videoView2);
MediaController mc = new MediaController(getApplicationContext());
mc.setAnchorView(vv);
mc.setMediaPlayer(vv);
Uri video = Uri.parse("http://techslides.com/demos/sample-videos/small.mp4");
vv.setVideoURI(video);
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
vv.start();
}
});
dialog.show();
}
});
清单文件中缺少以下行。
<uses-permission android:name="android.permission.INTERNET" />
我想在 Dialog
框中播放视频以响应 ListView
itemclicked 事件。 Dialog
打开,我收到以下消息:
Can't play this video
代码如下:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
final Dialog dialog = new Dialog(aikiorder.this);
dialog.setContentView(R.layout.aikiitemsample);
dialog.setTitle(aikiNames[position]);
Button b = (Button) dialog.findViewById(R.id.button2);
b.setText(getString(R.string.closeVideoText) + " - " + aikiNames[position]);
dialog.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
final VideoView vv = (VideoView) dialog.findViewById(R.id.videoView2);
MediaController mc = new MediaController(getApplicationContext());
mc.setAnchorView(vv);
mc.setMediaPlayer(vv);
Uri video = Uri.parse("http://techslides.com/demos/sample-videos/small.mp4");
vv.setVideoURI(video);
vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
vv.start();
}
});
dialog.show();
}
});
清单文件中缺少以下行。
<uses-permission android:name="android.permission.INTERNET" />