gpt4 book ai didi

android - 抱歉,此视频无法在 videoview 中播放?

转载 作者:行者123 更新时间:2023-11-29 14:06:51 25 4
gpt4 key购买 nike

friend ,

我正在使用以下代码在我的应用程序中显示 mp4 视频并面临以下问题

我在 google 和 stackoverflow 上看到了很多与这个问题相关的帖子,但每个人都给出了自己的建议,没有一个共同的答案。

1) 我无法在模拟器中看到视频2) 在不同的手机上有时会播放很少的视频,但大多数时候会显示上述消息。

我的代码

VideoView myVideoView = (VideoView)findViewById(R.id.videoview);

String viewSource ="http://dev.hpac.dev-site.org/sites/default/files/videos/about/mobile.mp4";

myVideoView.setVideoURI(Uri.parse(viewSource));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();

任何人指导我这个问题的解决方案是什么任何帮助将不胜感激。

最佳答案

您可以使用您的文件制作输出流并获取流的绝对路径,然后将路径放入视频 View

    private String getDataSource(String path) throws IOException {
if (!URLUtil.isNetworkUrl(path)) {
return path;
} else {
URL url = new URL(path);
URLConnection cn = url.openConnection();
cn.connect();
InputStream stream = cn.getInputStream();
if (stream == null)
throw new RuntimeException("stream is null");
File temp = File.createTempFile("mediaplayertmp", "dat");
temp.deleteOnExit();
String tempPath = temp.getAbsolutePath();
@SuppressWarnings("resource")
FileOutputStream out = new FileOutputStream(temp);
byte buf[] = new byte[128];
do {
int numread = stream.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
try {
stream.close();
} catch (IOException ex) {
Log.e(TAG, "error: " + ex.getMessage(), ex);
}
return tempPath;
}
}

public void initVideo() {
try {

if (!mVideoView.isPlaying()) {

if (url > playList.size() - 1) {
url = 0;
}
String[] playurl = (playList.get(url)).split("\\.");
String urlExtention = playurl[playurl.length - 1];

if (urlExtention.equals("mp4")) {
playVideo(playList.get(url));
} else if (urlExtention.equals("jpg")
|| urlExtention.equals("jpeg")) {

Intent intentShedule = new Intent(Default_Player.this,
ImagePlayer.class);

intentShedule.putExtra("imagePath", playList.get(url));
intentShedule.putExtra("urlValue", url);
intentShedule.putExtra("playlistType", playlistType);
intentShedule.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intentShedule);
finish();
} else {
Intent intentShedule = new Intent(Default_Player.this,
WebContentView.class);

intentShedule.putExtra("webPath", playList.get(url));
intentShedule.putExtra("urlValue", url);
intentShedule.putExtra("playlistType", playlistType);
intentShedule.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intentShedule);
finish();
}

}

mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
System.out.println("set on error listner");

//do somthing if alert this video can not be played

return false;
}
});

mVideoView
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

public void onCompletion(MediaPlayer vmp) {

playnew();
}
});

} catch (Exception e) {

}

// TODO Auto-generated method stub

}

如果警告此视频无法播放,则在错误监听器上使用

关于android - 抱歉,此视频无法在 videoview 中播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410195/

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