我想播放来自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);
}
答案 0 :(得分:0)
使用VideoView而不是WebView。
VideoView video = (VideoView)findViewById(R.id.video);
video.setVideoURI(Uri.parse("insert rtsp here"));
video.start();
答案 1 :(得分:0)
我前段时间遇到过这个问题。诀窍是确定视频的实际网址,然后使用MediaPlayer
播放视频。
比方说,您正在关注此视频:http://www.youtube.com/watch?v=ou87i6Oq5M0 - 请注意视频标记:ou87i6Oq5M0
。要获取实际视频流的网址,您可以检索此资源:http://gdata.youtube.com/feeds/api/videos/ou87i6Oq5M0?v=2 - 这将返回YouTube视频的元数据,包括流的实际网址:
<?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/"CkUCSH47eCp7I2A9Wh5WF00."'><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 & 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&f=videos&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&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 & Politics' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>News</media:category><media:content url='http://www.youtube.com/v/ou87i6Oq5M0?version=3&f=videos&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&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>
不要过于担心复杂性。你只需要这个元素:
<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
元素 - 您需要具有type=
video / 3gpp`内容类型的元素。从中获取URL - 这是视频流的URL。
现在使用VideoView
来显示您的视频:
VideoView video = (VideoView)findViewById(R.id.video_player);
video.setVideoURI(Uri.parse(videoUrl));
video.start();
在此代码中,videoUrl
是如上所示的网址,具体而言,
rtsp://r8---sn-5hn7su7l.c.youtube.com/CiILENy73wIaGQnN5KqjizvvohMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp