Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Youtube视频未在android的InApp中播放_Android_Video_Youtube - Fatal编程技术网

Youtube视频未在android的InApp中播放

Youtube视频未在android的InApp中播放,android,video,youtube,Android,Video,Youtube,在我的应用程序中,Youtube视频在InApp中完美播放。但肯定是在我播放视频和视频未播放时收到以下警告消息“抱歉,此视频无法播放”的前两天。我尝试了不同的youtube视频链接,但没有希望。如果我使用此代码: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/embed/Ai47z6qh8S0"));

在我的应用程序中,Youtube视频在InApp中完美播放。但肯定是在我播放视频和视频未播放时收到以下警告消息“抱歉,此视频无法播放”的前两天。我尝试了不同的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;
    }
公共静态字符串calculateYouTubeUrl(字符串pYouTubeFmtQuality,布尔pFallback,
字符串pYouTubeVideoId)引发IOException,
ClientProtocolException,不支持的编码异常{
字符串lUriStr=null;
HttpClient lClient=new DefaultHttpClient();
HttpGet lGetMethod=新的HttpGet(openyoutubeplayepractivity.YOUTUBE\u VIDEO\u INFORMATION\u URL+
pYouTubeVideoId);
HttpResponse lResp=null;
lResp=lClient.execute(lGetMethod);
ByteArrayOutputStream lBOS=新建ByteArrayOutputStream();
字符串lInfoStr=null;
lResp.getEntity().writeTo(杠杆收购);
lInfoStr=新字符串(lBOS.toString(“UTF-8”);
字符串[]lArgs=lInfoStr.split(“&”);
Map lArgMap=newhashmap();
对于(int i=0;i=2){
lArgMap.put(lArgValStrArr[0],URLDecoder.decode(lArgValStrArr[1]);
}
}
}
//从参数中找出URI字符串
//填充视频格式列表
字符串lFmtList=urldecker.decode(lArgMap.get(“fmt_list”);
ArrayList lFormats=新的ArrayList();
如果(null!=lFmtList){
字符串lFormatStrs[]=lFmtList.split(“,”);
for(字符串lFormatStr:lFormatStrs){
格式lFormat=新格式(lFormatStr);
lFormat.add(lFormat);
}
}
//填充视频流的列表
字符串lStreamList=lArgMap.get(“url_encoded_fmt_stream_map”);
if(null!=lStreamList){
字符串lStreamStrs[]=lStreamList.split(“,”);
ArrayList lStreams=新的ArrayList();
用于(字符串lStreamStr:lStreamStrs){
VideoStream lStream=新的视频流(lStreamStr);
l流。添加(l流);
}   
//在视频格式列表中搜索给定格式
//如果有,请选择相应的流
//否则,如果请求回退,请检查下一个较低的格式
int lFormatId=Integer.parseInt(pYouTubeFmtQuality);
格式lSearchFormat=新格式(lFormatId);
而(!lFormats.contains(lSearchFormat)和&pFallback){
int lOldId=lSearchFormat.getId();
int lNewId=getSupportedFallbackId(lOldId);
if(lOldId==lNewId){
打破
}
lSearchFormat=新格式(lNewId);
}
int-lIndex=lFormats.indexOf(lSearchFormat);
如果(林德克斯>=0){
VideoStream lSearchStream=lStreams.get(lIndex);
lUriStr=lSearchStream.getUrl();
}
}       
//返回URI字符串。如果格式为空(如果启用,则为回退格式),则可能为空
//在视频格式列表中找不到
返回lUriStr;
}
请帮我解决这个问题


感谢Santanu

这种youtube链接在android应用程序上不起作用,尽管它在浏览器上运行良好。要使其在应用程序上工作,您需要先获得视频的RTSP链接。
参考这一点,看看是否能找到解决方案。
android上的youtube链接示例(我已经测试过这个): rtsp://v2.cache6.c.youtube.com/CjgLENy73wIaLwn_aij76iwMRRMYESARFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRgnfqw4Jajx8xPDA==/0/0/0/video.3gp


试试这个或者

您需要打开硬件加速功能

Intent i=newintent(Intent.ACTION\u视图);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("Video url"));
VideoActivity.this.startActivity(i);


     //And add below code in Manifest.xml file.

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
i、 setData(Uri.parse(“视频url”); 视频活动。这个。星触觉(i); //并在Manifest.xml文件中添加以下代码。
您是否尝试过使用iframe播放相同的视频。
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("Video url"));
VideoActivity.this.startActivity(i);


     //And add below code in Manifest.xml file.

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />