gpt4 book ai didi

java - 视频确实在 Android 模拟器中显示

转载 作者:行者123 更新时间:2023-12-01 12:30:20 25 4
gpt4 key购买 nike

当我运行项目时,视频不显示。我还在文件浏览 -> mnt -> sdcard -> a.mp4 中推送 a.mp4 文件,但运行项目时视频仍然无法播放。请任何人帮助我下面的代码哪里有错误。

    public class MainActivity extends Activity {

VideoView video_player_view;
SurfaceView sur_view;
MediaController media_controller;
DisplayMetrics dm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void getInit()
{
video_player_view = (VideoView)findViewById(R.id.videoView1);
media_controller = new MediaController(this);
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.heightPixels;
video_player_view.setMinimumHeight(height);
video_player_view.setMinimumWidth(width);
video_player_view.setMediaController(media_controller);
video_player_view.setVideoPath("/mnt/sdcard/a.mp4");
video_player_view.start();
}
}

最佳答案

你没有调用getInit()方法

    public class MainActivity extends Activity {

VideoView video_player_view;
SurfaceView sur_view;
MediaController media_controller;
DisplayMetrics dm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);\
getInit();
}

public void getInit()
{
video_player_view = (VideoView)findViewById(R.id.videoView1);
media_controller = new MediaController(this);
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.heightPixels;
video_player_view.setMinimumHeight(height);
video_player_view.setMinimumWidth(width);
video_player_view.setMediaController(media_controller);
video_player_view.setVideoPath("/mnt/sdcard/a.mp4");
video_player_view.start();
}
}

模拟器在播放某些视频时确实存在问题,因此我始终在实际设备上进行所有视频测试。当视频在模拟器上运行时,它通常充其量非常慢(1fps,偏移声音)。

关于java - 视频确实在 Android 模拟器中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25967570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com