gpt4 book ai didi

java - MediaPlayer是否可以打开”?

转载 作者:行者123 更新时间:2023-12-03 06:15:09 24 4
gpt4 key购买 nike

我搜索并尝试了Stack / Android文档或教程中找到的所有解决方案
知道为什么我无法在VideoView中播放视频URL(例如,来自YT)吗?
在AndroidManifest文件中添加了INTERNET权限,这也是我的代码的一部分:

String url = "http://www.youtube.com/watch?v="+eventData.getYoutube_id();
final VideoView vw = views.getVideoView(R.id.vw_media);
vw.setVisibility(View.VISIBLE);

try{
MediaController mc = new MediaController(context);
mc.setAnchorView(mc);
Uri video = Uri.parse(url);
vw.setMediaController(mc);
vw.setVideoURI(video);
catch (Exception e){
Log.d(TAG, e.getMessage());
}
vw.requestFocus();
vw.start();
我在应用中收到一条消息,提示“无法播放此视频”
enter image description here
Logcat:
MediaPlayer:无法打开 http://www.youtube.com/watch?v=sfkmKzr8zgg:java.io.FileNotFoundException:无内容提供程序: http://www.youtube.com/watch?v=sfkmKzr8zgg
根本无法解决。
顺便说一句,Android版本是7.0

最佳答案

private class YourAsyncTask extends AsyncTask<Void, Void, Void>
{
ProgressDialog progressDialog;

@Override
protected void onPreExecute()
{
super.onPreExecute();
progressDialog = ProgressDialog.show(AlertDetail.this, "", "Loading Video wait...", true);
}

@Override
protected Void doInBackground(Void... params)
{
try
{
String url = "http://www.youtube.com/watch?v=1FJHYqE0RDg";
videoUrl = getUrlVideoRTSP(url);
Log.e("Video url for playing=========>>>>>", videoUrl);
}
catch (Exception e)
{
Log.e("Login Soap Calling in Exception", e.toString());
}
return null;
}

@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
progressDialog.dismiss();
videoView.setVideoURI(Uri.parse(videoUrl));
MediaController mc = new MediaController(AlertDetail.this);
videoView.setMediaController(mc);
videoView.requestFocus();
videoView.start();
mc.show();
}

}

public static String getUrlVideoRTSP(String urlYoutube)
{
try
{
String gdy = "http://gdata.youtube.com/feeds/api/videos/";
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
String id = extractYoutubeId(urlYoutube);
URL url = new URL(gdy + id);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
Document doc = documentBuilder.parse(connection.getInputStream());
Element el = doc.getDocumentElement();
NodeList list = el.getElementsByTagName("media:content");///media:content
String cursor = urlYoutube;
for (int i = 0; i < list.getLength(); i++)
{
Node node = list.item(i);
if (node != null)
{
NamedNodeMap nodeMap = node.getAttributes();
HashMap<String, String> maps = new HashMap<String, String>();
for (int j = 0; j < nodeMap.getLength(); j++)
{
Attr att = (Attr) nodeMap.item(j);
maps.put(att.getName(), att.getValue());
}
if (maps.containsKey("yt:format"))
{
String f = maps.get("yt:format");
if (maps.containsKey("url"))
{
cursor = maps.get("url");
}
if (f.equals("1"))
return cursor;
}
}
}
return cursor;
}
catch (Exception ex)
{
Log.e("Get Url Video RTSP Exception======>>", ex.toString());
}
return urlYoutube;

}

protected static String extractYoutubeId(String url) throws MalformedURLException
{
String id = null;
try
{
String query = new URL(url).getQuery();
if (query != null)
{
String[] param = query.split("&");
for (String row : param)
{
String[] param1 = row.split("=");
if (param1[0].equals("v"))
{
id = param1[1];
}
}
}
else
{
if (url.contains("embed"))
{
id = url.substring(url.lastIndexOf("/") + 1);
}
}
}
catch (Exception ex)
{
Log.e("Exception", ex.toString());
}
return id;
}

关于java - MediaPlayer是否可以打开<url>”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44840712/

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