在我的应用程序中,Youtube 视频在 InApp 中完美播放。但肯定是在播放视频和视频未播放时收到以下警告消息“抱歉,此视频无法播放”的前 2 天。我尝试了不同的 youtube 视频链接,但没有希望。如果我使用此代码:
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/embed/Ai47z6qh8S0"));
startActivity(browserIntent);
视频正在浏览器中播放。但我需要在应用程序中播放此视频。
以前我使用以下代码创建 youtube url
public static String calculateYouTubeUrl(String pYouTubeFmtQuality, boolean pFallback,
String pYouTubeVideoId) throws IOException,
ClientProtocolException, UnsupportedEncodingException {
String lUriStr = null;
HttpClient lClient = new DefaultHttpClient();
HttpGet lGetMethod = new HttpGet(OpenYouTubePlayerActivity.YOUTUBE_VIDEO_INFORMATION_URL +
pYouTubeVideoId);
HttpResponse lResp = null;
lResp = lClient.execute(lGetMethod);
ByteArrayOutputStream lBOS = new ByteArrayOutputStream();
String lInfoStr = null;
lResp.getEntity().writeTo(lBOS);
lInfoStr = new String(lBOS.toString("UTF-8"));
String[] lArgs=lInfoStr.split("&");
Map<String,String> lArgMap = new HashMap<String, String>();
for(int i=0; i<lArgs.length; i++){
String[] lArgValStrArr = lArgs[i].split("=");
if(lArgValStrArr != null){
if(lArgValStrArr.length >= 2){
lArgMap.put(lArgValStrArr[0], URLDecoder.decode(lArgValStrArr[1]));
}
}
}
//Find out the URI string from the parameters
//Populate the list of formats for the video
String lFmtList = URLDecoder.decode(lArgMap.get("fmt_list"));
ArrayList<Format> lFormats = new ArrayList<Format>();
if(null != lFmtList){
String lFormatStrs[] = lFmtList.split(",");
for(String lFormatStr : lFormatStrs){
Format lFormat = new Format(lFormatStr);
lFormats.add(lFormat);
}
}
//Populate the list of streams for the video
String lStreamList = lArgMap.get("url_encoded_fmt_stream_map");
if(null != lStreamList){
String lStreamStrs[] = lStreamList.split(",");
ArrayList<VideoStream> lStreams = new ArrayList<VideoStream>();
for(String lStreamStr : lStreamStrs){
VideoStream lStream = new VideoStream(lStreamStr);
lStreams.add(lStream);
}
//Search for the given format in the list of video formats
// if it is there, select the corresponding stream
// otherwise if fallback is requested, check for next lower format
int lFormatId = Integer.parseInt(pYouTubeFmtQuality);
Format lSearchFormat = new Format(lFormatId);
while(!lFormats.contains(lSearchFormat) && pFallback ){
int lOldId = lSearchFormat.getId();
int lNewId = getSupportedFallbackId(lOldId);
if(lOldId == lNewId){
break;
}
lSearchFormat = new Format(lNewId);
}
int lIndex = lFormats.indexOf(lSearchFormat);
if(lIndex >= 0){
VideoStream lSearchStream = lStreams.get(lIndex);
lUriStr = lSearchStream.getUrl();
}
}
//Return the URI string. It may be null if the format (or a fallback format if enabled)
// is not found in the list of formats for the video
return lUriStr;
}
请帮我弄清楚这个问题。
谢谢桑塔努