我想知道如何将Youtube视频放到html页面中。我已经搜索了几个小时,以下是我尝试的:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type='text/javascript' src='Scripts/swfobject.js'></script>
<script type='text/javascript'>
swfobject.registerObject("playerID", "9.0.0");
</script>
<script type='text/javascript' src='Scripts/mediaplayer/jwplayer.js'></script>
</head>
<body>
<script type='text/javascript' src='Scripts/mediaplayer/jwplayer.js'></script>
<div id='mediaplayer'></div>
<script type="text/javascript">
var flashvars = {
'file': 'http://www.youtube.com/watch?v=YE7VzlLtp-4',
'controlbar': 'bottom'
};
var params = {
'allowfullscreen': 'true',
'allowscriptaccess': 'always'
};
var attributes = {
'id': 'playerID',
'name': 'playerID'
};
swfobject.embedSWF('Scripts/mediaplayer/player.swf', 'mediaplayer', '480', '360', '9', 'false', flashvars, params, attributes);
</script>
</body>
</html>
和
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type='text/javascript' src='./Scripts/swfobject.js'></script>
</head>
<body>
<script type='text/javascript' src='./Scripts/mediaplayer/jwplayer.js'></script>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': './Scripts/mediaplayer/player.swf',
'file': 'http://www.youtube.com/v/K_sev04KfeU?version',
'controlbar': 'bottom',
'width': '470',
'height': '320'
});
</script>
</body>
</html>
和
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type='text/javascript' src='./Scripts/mediaplayer/jwplayer.js'></script>
</head>
<body>
<div id='mediaplayer'></div>
<script type="text/javascript">
jwplayer('mediaplayer').setup({
'flashplayer': './Scripts/mediaplayer/player.swf',
'id': 'playerID',
'width': '480',
'height': '270',
'file': 'XSGBVzeBUbk',
'provider': 'youtube',
'plugins': {
'hd-2': {}
}
});
</script>
</body>
</html>
以及数十种变体(包括registerObject)。。。我想知道是否有人能给我举个例子。zip链接。
您可以使用他们的示例脚本并修改上传播放器的路径
<div id="movieframe">
<script type="text/javascript" src="http://www.mysite.com/jwplayer/jwplayer.js"></script>
<div id="mediaspace" style='width:640px;height:480px;'></div>
<script type='text/javascript'>
jwplayer('mediaspace').setup({
'flashplayer': 'http://www.mysite.com/jwplayer/player.swf',
'file': 'http://www.youtube.com/watch?v=YE7VzlLtp-4',
'image': 'http://www.mysite.com/graphics/splash.jpg',
'controlbar': 'bottom',
'width': '640',
'height': '480'
});
</script>
</div>
</div>
您只需要调用此脚本一次
<script type="text/javascript" src="http://www.mysite.com/jwplayer/jwplayer.js">
它可以在<head>
标签中,也可以在您显示它之前,但您不需要两者都有。通常,jwplayer.js和player.swf在同一目录中。如果你没有包含正确的路径,它将不起作用——你的例子使用了几个不同的路径。
我通过将script标记移到顶部来解决问题。谢谢你的帮助。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="tr">
<head>
<title>My Title</title>
<script type="text/javascript" src="../Scripts/jwplayer/jwplayer.js"></script>
<meta name="keywords" content="foreign trade, hazelnut, livestocks, sunflower, rice, wheat, lentil, sunflower oil" />
<meta name="description" content="Comparative Nutrition Values: Brown & White Grain Rice table" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-store, no-cache, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="expires" content="01 jan 1970 00:00:00 gmt" />
<meta http-equiv="last-modified" content="01 jan 1970 00:00:00 gmt" />
<meta http-equiv="if-modified-since" content="01 jan 1970 00:00:00 gmt" />
<link href="../css/main.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="icon" type="image/x-ico" href="../favicon.ico" />
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico" />
</head>