java视频播放器无法使用Android Studio
我正在尝试添加一个视频播放按钮点击与安卓工作室。 但是,当我单击按钮时,emulator屏幕上会出现“抱歉,此视频无法播放”消息框
你能帮我看看哪里出了问题吗。 下面是我实现目标的代码
Trialvideo。java
package 安卓.com.trialvideo;
import 安卓.app.Activity;
import 安卓.graphics.PixelFormat;
import 安卓.media.MediaPlayer;
import 安卓.net.Uri;
import 安卓.os.Bundle;
import 安卓.view.View;
import 安卓.view.View.OnClickListener;
import 安卓.widget.Button;
import 安卓.widget.MediaController;
import 安卓.widget.VideoView;
public class TrialVideoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** // Video view: to view our video
VideoView video = (VideoView) findViewById(R.id.surface_view);
//set video path to our video(in this case man-cheetah-gazalle.3gp)
video.setVideoPath("/raw/jeewan.mp4");
video.start();
**/
final Button play =(Button)findViewById(R.id.play);
play.setOnClickListener(new OnClickListener(){
public void onClick(View V){
videoPlayer();
}
});}
public void videoPlayer(){
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView videoHolder = (VideoView)findViewById(R.id.surface_view);
videoHolder.setMediaController(new MediaController(this));
videoHolder.setVideoPath("/TrialVideo/raw/lic.3gp");
videoHolder.requestFocus();
videoHolder.start();
}
}
main。xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:orientation="vertical"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
>
<Button
安卓:layout_height="50dip"
安卓:text="play"
安卓:id="@+id/play"
安卓:layout_width="50dip"
>
</Button>
<VideoView 安卓:id="@+id/surface_view"
安卓:layout_width="475px"
安卓:layout_height="440px"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:orientation="vertical"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
>
<Button
安卓:layout_height="50dip"
安卓:text="play"
安卓:id="@+id/play"
安卓:layout_width="50dip"
>
</Button>
<VideoView 安卓:id="@+id/surface_view"
安卓:layout_width="475px"
安卓:layout_height="440px"
/>
</LinearLayout>
# 1 楼答案
您好,请尝试以下代码:
视频播放。爪哇
梅因。xml
将视频放在原始文件夹中,然后运行代码。有时视频无法在模拟器上正确显示,请尝试在实际设备上进行检查
# 2 楼答案
Android没有C:驱动器。您需要将视频文件放在设备上(例如,将其复制到设备的外部存储器),然后为
VideoView
提供文件的适当路径(例如,使用Environment.getExternalStorageDirectory()
)