解析 – 将url_encoded_fmt_stream_map解码为有效的Url

我正在使用url_encoded_fmt_stream_map来获取Youtube VideoStream列表“urls”.

我想使用这些网址在我的VideoView中显示Youtube视频.

我的方法几乎返回一个包含这样的字符串的字符串数组:

sig=3E0D90E459ADEF9F88553D716B9275930A8AA418.AD0319F9287244E34CCA97F7DE245C0606DD46C5&itag=45&fallback_host=tc.v22.cache5.c.youtube.com&url=http%3A%2F%2Fr4—sn-uigxx50n-8pxl.c.youtube.com%2Fvideoplayback%3Fsparams%3Dcp%252Cid%252Cip%252Cipbits%252Citag%252Cratebypass%252Csource%252Cupn%252Cexpire%26id%3D4e6580527662c67d%26cp%3DU0hVSVlQV19FUENONV9RSkFIOnZ3SkZXb3hfdUdp%26source%3Dyoutube%26fexp%3D919110%252C913564%252C916624%252C932000%252C906383%252C902000%252C919512%252C929903%252C931202%252C900821%252C900823%252C931203%252C931401%252C909419%252C913566%252C908529%252C930807%252C919373%252C930803%252C906836%252C920201%252C929602%252C930101%252C930603%252C900824%252C910223%26ms%3Dau%26mv%3Dm%26mt%3D1364933359%26sver%3D3%26itag%3D45%26key%3Dyt1%26ip%3D178.115.248.80%26newshard%3Dyes%26upn%3DNLMBgU-0oUc%26expire%3D1364959706%26ipbits%3D8%26ratebypass%3Dyes&quality=hd720&type=video%2Fwebm%3B+codecs%3D%22vp8.0%2C+vorbis%22

如果仔细查看它,可以看到此String实际上包含有效信息.不幸的是我不知道如何从中提取有效的URL.

我该怎么办?

如果我使用上面的String创建一个URI并将其添加到我的VideoView,则会显示消息“无法播放此视频”.弹出.

最佳答案 您可能知道,youtube链接看起来像这样:

http://r6---sn-nhpax-ua8l.c.youtube.com/videoplayback?algorithm=throttle-factor&burst=40&cp=U0hVTFlTUV9HUUNONV9RTVVCOkk4ams1XzRlZUpq&cpn=qAthIxAZB16Q6_qB&expire=1367983127&factor=1.25&fexp=927900%2C919357%2C921716%2C916623%2C922911%2C931009%2C932000%2C932004%2C906383%2C904479%2C901208%2C925714%2C929119%2C931202%2C900821%2C900823%2C912518%2C911416%2C930807%2C919373%2C906836%2C926403%2C900824%2C912711%2C929606%2C910075&id=932a6c200e40b791&ip=84.228.249.95&ipbits=8&itag=34&key=yt1&ms=au&mt=1367957244&mv=m&newshard=yes&ratebypass=yes&signature=7E86D1813AE13CEB544CFF3749FBD042FF50EE91.AF7D6D9DCF286D291825630E733B3407683C46C9&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=t0jDC5Yk7Go

正如你所说,我们需要的所有参数都显示在你的字符串中.

我们需要从您的字符串中提取两个重要参数:url和signature.

链接最终应该如下所示:url“& signature =”sig.

您可以查看我的代码,从中提取youtube链接中的所有可用链接.它在java中为一个Android应用程序wriitten:link

点赞