"Deeplink"到带有HTML5 / Flash的MP3中的某个位置



是否有任何现有的代码示例,其中有可能做类似的事情沿着什么发生在YouTube上,即有可能'深链接'到视频中的某个位置,但对于MP3代替?

例如,作为如何在YouTube上完成的一个例子,正常的链接是:http://www.youtube.com/watch?v=W3ZHPJT2Kp4

可以在某个时间点右键点击播放位置图标,选择"复制当前时间视频URL",例如在14秒点选择,得到如下链接:http://www.youtube.com/watch?feature=player_detailpage& v = W3ZHPJT2Kp4 # t = 14年代

我想做同样的事情,通过深度链接到我想在网页上播放的MP3。

我见过一些HTML5 MP3播放器,如Jplayer (http://www.jplayer.org),但我还没有看到它提供这种功能。

有什么线索,提示,建议开始这样做吗?我想我更喜欢使用HTML5,但会考虑Flash。

更新(11/01/2012):我得到'TypeError: 'null'不是一个对象(评估'music。currentTime = att_hash['a']')当我点击' click Me!"按钮。

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<!-- Website Design By: www.happyworm.com -->
<title>Demo : jPlayer as an audio player</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="http://www.jplayer.org/latest/skin/blue.monday/jplayer.blue.monday.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jplayer.org/latest/js/jquery.jplayer.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
m4a:"http://www.jplayer.org/audio/m4a/TSP-01-Cro_magnon_man.m4a"
});
},
swfPath: "js",
supplied: "m4a, oga",
wmode: "window"
});
});
//]]>
</script>
</head>
<body>
<div id="jquery_jplayer_1" class="jp-jplayer"></div>
<div id="jp_container_1" class="jp-audio">
<div class="jp-type-single">
<div class="jp-gui jp-interface">
<ul class="jp-controls">
<li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
<li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
<li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
<li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
</ul>
<div class="jp-progress">
<div class="jp-seek-bar">
<div class="jp-play-bar"></div>
</div>
</div>
<div class="jp-volume-bar">
<div class="jp-volume-bar-value"></div>
</div>
<div class="jp-time-holder">
<div class="jp-current-time"></div>
<div class="jp-duration"></div>
<ul class="jp-toggles">
<li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>
<li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>
</ul>
</div>
</div>
<div class="jp-title">
<ul>
<li>A Song</li>
</ul>
</div>
<div class="jp-no-solution">
<span>Update Required</span>
To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
</div>
</div>
</div>
<br><br>
<button id="gettime">Click Me!</button>
<input type="text" id="showtime">
<script language="javascript">                    
var music = document.getElementById('music') // Your <audio> object
var gettime = document.getElementById('gettime') // A 'get time' button
var showtime = document.getElementById('showtime') // An input text object for displaying the URL
gettime.addEventListener("click", function(){
showtime.value = window.location.protocol+'//'+window.location.host+window.location.pathname+'?a='+music.currentTime;
}, true);
window.addEventListener('load', function(){
var att_hash = get_url_variables()
if (att_hash) {
music.currentTime = att_hash['a']
}
}, true);
function get_url_variables() {
var att_hash = []
var var_array = window.location.search.split(/[?&]/)
for (i=0; i<var_array.length; i++) {
if (var_array[i] != "") {
var att_var = var_array[i].split("=",2)
att_hash[att_var[0]]=att_var[1]
}
}
return att_hash;
}
</script>
</body>
</html>

用HTML5/javascript实现你想要的最大问题是它不提供对剪贴板的访问。但是,如果您不介意为用户提供一个手动复制的URL,这是相当容易完成的。据我所知,如果你想写入用户的剪贴板,你需要使用类似flash的" helper object "之类的东西。但是我没有flash的经验,所以不能在这里帮助你。

audio对象提供浮点currentTime,可以很容易地设置或检索。同时,您可以通过各种窗口检索URL和相关变量。位置变量。这里我编写了get_url_variables函数,将它们传递到散列中。如果您正在使用jquery之类的库,我强烈怀疑它提供了类似的功能,并且可能比我的快速示例稳定得多。

编辑:哎呀,我错过了你对右键菜单的要求。我从来都不喜欢这个,但是这里有关于添加右键响应的讨论。

var music = document.getElementById('music') // Your <audio> object
var gettime = document.getElementById('gettime') // A 'get time' button
var showtime = document.getElementById('showtime') // An input text object for displaying the URL
gettime.addEventListener("click", function(){
        showtime.value = window.location.protocol+'//'+window.location.host+window.location.pathname+'?a='+music.currentTime;
    }, true);
window.addEventListener('load', function(){
        var att_hash = get_url_variables()
        if (att_hash) {
            music.currentTime = att_hash['a']
        }
    }, true);
function get_url_variables() {
    var att_hash = []
    var var_array = window.location.search.split(/[?&]/)
    for (i=0; i<var_array.length; i++) {
        if (var_array[i] != "") {
            var att_var = var_array[i].split("=",2)
            att_hash[att_var[0]]=att_var[1]
        }
    }
    return att_hash;
}

最新更新