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
如何在Android上播放视频?_Android_Video_Android Youtube Api - Fatal编程技术网

如何在Android上播放视频?

如何在Android上播放视频?,android,video,android-youtube-api,Android,Video,Android Youtube Api,我只想播放youtube上的视频。但是我使用的代码显示了更多的细节,就像我从网站上打开它一样。我怎样才能获得建议视频、评论、信息等细节。。。。我只想在应用程序上播放视频。任何帮助都将不胜感激:)谢谢 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

我只想播放youtube上的视频。但是我使用的代码显示了更多的细节,就像我从网站上打开它一样。我怎样才能获得建议视频、评论、信息等细节。。。。我只想在应用程序上播放视频。任何帮助都将不胜感激:)谢谢

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

            WebView webView1 =(WebView)findViewById(R.id.webView1);
    webView1.getSettings().setAllowFileAccess(true);
    webView1.getSettings().setLoadWithOverviewMode(false);
    webView1.getSettings().setUseWideViewPort(false);
    webView1.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    webView1.getSettings().setSupportMultipleWindows(false);
    webView1.setWebChromeClient(new WebChromeClient());
    webView1.setWebViewClient(new WebViewClient());
    webView1.setWebViewClient(new Callback());
    webView1.getSettings().setJavaScriptEnabled(true);
    webView1.getSettings().setPluginState(PluginState.ON);
            String video_path = "http://www.youtube.com/watch?v=jtrltr-uIvw";
            Uri uri = Uri.parse(video_path);
            uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

使用VideoView而不是WebView

VideoView video = (VideoView)findViewById(R.id.video);
video.setVideoURI(Uri.parse("insert rtsp here"));
video.start();

我不久前就有这个问题。诀窍是确定视频的实际URL,然后使用
MediaPlayer
播放视频

比方说,您正在关注此视频:-注意视频标签:
ou87i6Oq5M0
。要获取实际视频流的URL,可以检索以下资源:-这将返回youtube视频的元数据,包括流的实际URL:

<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/&quot;CkUCSH47eCp7I2A9Wh5WF00.&quot;'><id>tag:youtube.com,2008:video:ou87i6Oq5M0</id><published>2013-09-01T11:21:22.000Z</published><updated>2013-11-29T04:44:29.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='News' label='News &amp; Politics'/><title>WORLDS FASTEST propellar driven AIRCRAFT Russian Tu 95MC Nuclear Bomber</title><content type='application/x-shockwave-flash' src='http://www.youtube.com/v/ou87i6Oq5M0?version=3&amp;f=videos&amp;app=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.in-response-to' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/hdFswfC_Egk?v=2'/><link rel='
alternate' type='text/html' href='http://www.youtube.com/watch?v=ou87i6Oq5M0&amp;feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0/related?v=2'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=ou87i6Oq5M0'/><link rel='http://gdata.youtube.com/schemas/2007#uploader' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/D8bmW4A7eYzHrW7sXwsqwQ?v=2'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0?v=2'/><author><name>ArmedForcesUpdate</name><uri>http://gdata.youtube.com/feeds/api/users/ArmedForcesUpdate</uri><yt:userId>D8bmW4A7eYzHrW7sXwsqwQ</yt:userId></author><yt:accessControl action='comment' permission='allowed'/><yt:accessControl action='commentVote' permission='allowed'/><yt:accessControl action='videoRespond' permission='moderated'/><yt:
accessControl action='rate' permission='allowed'/><yt:accessControl action='embed' permission='allowed'/><yt:accessControl action='list' permission='allowed'/><yt:accessControl action='autoPlay' permission='allowed'/><yt:accessControl action='syndicate' permission='allowed'/><gd:comments><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#comments' href='http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0/comments?v=2' countHint='45'/></gd:comments><media:group><media:category label='News &amp; Politics' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>News</media:category><media:content url='http://www.youtube.com/v/ou87i6Oq5M0?version=3&amp;f=videos&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='165' yt:format='5'/><media:content url='rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='165' yt:format='1'/
><media:content url='rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='165' yt:format='6'/><media:credit role='uploader' scheme='urn:youtube' yt:display='ArmedForcesUpdate' yt:type='partner'>armedforcesupdate</media:credit><media:description type='plain'>Russian Aircraft The Tupolev Tu-95 (Russian: Туполев Ту--95; NATO reporting name: Bear) is a large, four-engine turboprop-powered strategic bomber and missile platform. First flown in 1952, the Tu-95 entered service with the Soviet Union in 1956 and is expected to serve the Russian Air Force until at least 2040.[1] A naval development of the bomber is designated Tu-142.

The aircraft has four Kuznetsov NK-12 engines, developed by the Kuznetsov Design Bureau with participation of Ferdinand Brandner and other captured German engineers, each driving contra-rotating propellers. An airliner variant Tu-114 holds the record as the world's fastest propeller-driven aircraft. Some experimental aircraft were designed for theoretically higher speeds, but none attained or registered them. It also remains the only turboprop-powered strategic bomber in operational use. Its distinctively swept-back wings are at 35°, a very sharp angle by the standards of propeller-driven aircraft, and justified by its operating speeds and altitudes. Its blades, which rotate faster than the speed of sound, according to one media source, make it arguably the noisiest military aircraft on earth,[2] with only the experimental 1950s era Republic XF-84H "Thunderscreech" turboprop powered American fighter design as a likely rival.[citation needed] It was reportedly so loud that the underwater Hydrophones of 
submerged submarines and SOSUS could detect it.
Russia Listeni/ˈrʌʃə/ or /ˈrʊʃə/ (Russian: Россия, tr. Rossiya, IPA: [rɐˈsʲijə] ( listen)), also officially known as the Russian Federation[10] (Russian: Российская Федерация, tr. Rossiyskaya Federatsiya, IPA: [rɐˈsʲijskəjə fʲɪdʲɪˈrat͡sɨjə] ( listen)), is a country in northern Eurasia.[11] It is a federal semi-presidential republic, comprising 83 federal subjects. From northwest to southeast, Russia shares land borders with Norway, Finland, Estonia, Latvia, Lithuania and Poland (both with Kaliningrad Oblast), Belarus, Ukraine, Georgia, Azerbaijan, Kazakhstan, China, Mongolia, and North Korea. It shares maritime borders with Japan by the Sea of Okhotsk and the US state of Alaska across the Bering Strait. At 17,075,400 square kilometres (6,592,800 sq mi), Russia is the largest country in the world, covering more than one-eighth of the Earth's inhabited land area. Russia is also the world's ninth most populous nation with 143 million people as of 2012.[12] Extending across the entirety of northern Asia and much 
of Europe, Russia spans nine time zones and incorporates a wide range of environments and landforms.
An aircraft is a machine that is able to fly by gaining support from the air, or, in general, the atmosphere of a planet. It counters the force of gravity by using either static lift or by using the dynamic lift of an airfoil,[1] or in a few cases the downward thrust from jet engines.

The human activity that surrounds aircraft is called aviation. Crewed aircraft are flown by an onboard pilot, but unmanned aerial vehicles may be remotely controlled or self-controlled by onboard computers. Aircraft may be classified by different criteria, such as lift type, propulsion, usage and others.
The Russian Air Force (Russian: Военно-воздушные cилы России, tr. Voyenno-Vozdushnye Sily Rossii) is the aerial warfare service branch of the Armed Forces of the Russian Federation. It is currently under the command of Lieutenant General Viktor Bondarev. The Russian Navy has its own air arm, the Russian Naval Aviation, which is the former Soviet Aviatsiya Voyenno Morskogo Flota ("Naval Aviation"), or AV-MF).

The Air Force was formed from parts of the former Soviet Air Forces after the dissolution of the Soviet Union in 1991--92. Boris Yeltsin's creation of the Ministry of Defence of the Russian Federation on 7 May 1992, can be taken as a convenient formation date for the new Air Force. Since that time, the Air Force has suffered severe setbacks due to lack of resources, and has constantly shrunk in size. Since Vladimir Putin became President of the Russian Federation however, much more money has been allocated to the Armed Forces as a whole.
The United States Air Force (USAF) is the aerial warfare service branch of the United States Armed Forces and one of the seven American uniformed services. Initially part of the United States Army, the USAF was formed as a separate branch of the military on 18 September 1947 under the National Security Act of 1947.[5] It is the most recent branch of the U.S. military to be formed, and is the largest and one of the world's most technologically advanced air forces. The USAF articulates its core functions as Nuclear Deterrence Operations, Special Operations, Air Superiority, Global Integrated ISR, Space Superiority, Command and Control, Cyberspace Superiority, Personnel Recovery, Global Precision Attack, Building Partnerships, Rapid Global Mobility and Agile.[6]
Vladimir Vladimirovich Putin</media:description><media:keywords/><media:license type='text/html' href='http://www.youtube.com/t/terms'>youtube</media:license><media:player url='http://www.youtube.com/watch?v=ou87i6Oq5M0&amp;feature=youtube_gdata_player'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/default.jpg' height='90' width='120' time='00:01:22.500' yt:name='default'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/mqdefault.jpg' height='180' width='320' yt:name='mqdefault'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/1.jpg' height='90' width='120' time='00:00:41.250' yt:name='start'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/2.jpg' height='90' width='120' time='00:01:22.500' yt:name='middle'/><media:thumbnail url='http://i1.ytimg.com/vi/ou87i6Oq5M0/3.jpg' height='90' width='120' time='00:02:03.750' yt:name='end'/><media:title type='plain'
>WORLDS FASTEST propellar driven AIRCRAFT Russian Tu 95MC Nuclear Bomber</media:title><yt:duration seconds='165'/><yt:uploaded>2013-09-01T11:21:22.000Z</yt:uploaded><yt:uploaderId>UCD8bmW4A7eYzHrW7sXwsqwQ</yt:uploaderId><yt:videoid>ou87i6Oq5M0</yt:videoid></media:group><gd:rating average='4.855856' max='5' min='1' numRaters='111' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='0' viewCount='67834'/><yt:rating numDislikes='4' numLikes='107'/></entry>
在此代码中,
videoUrl
是如上所示的URL

rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp

你测试过这个吗?我对此表示怀疑。该URL未指向视频流-setVideoURI将失败。抱歉,您需要获取rtsp流。见下文:
VideoView video = (VideoView)findViewById(R.id.video_player);
video.setVideoURI(Uri.parse(videoUrl));
video.start();
rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp