如何使用setCurrentTime()设置开始时间偏移

时间:2011-09-30 04:24:43

标签: mediaelement.js

我有口头文字的录音,我想让用户在录音中的特定点开始录音,例如,开始时间后12.5秒。使用下面的示例代码,我该如何实现?

<audio id="player2" src="/player/media/AirReview-Landmarks-02-ChasingCorporate.mp3" type="audio/mp3" controls="controls"  preload="preload">
</audio>

<script>
var player = $('audio,video').mediaelementplayer(
{
        // the order of controls you want on the control bar (and other plugins below)
        features: ['playpause','progress','current','duration','tracks','volume','fullscreen'],
        audioWidth: 300,
        // enables Flash and Silverlight to resize to content size
        enableAutosize: true,
        startVolume: 0.7, 
        success: function(player, node) { 
                $('#' + node.id + '-mode').html('mode: ' + player.pluginType); 
        }
}
);
</script>

2 个答案:

答案 0 :(得分:0)

查找mediaelementplayer对象:

var myplayer = jQuery('#your_player')["0"];

以秒为单位设置时间(例如12.5):

myplayer.player.setCurrentTime(12.5);
myplayer.player.setCurrentRail();

:)

答案 1 :(得分:0)

我能够弄清楚如何使用外部链接控制mediaelement.js播放器。必须使用变量初始化播放器。

<video id="player1" width="720" height="406" controls="controls" preload="none">
    <source src="myvid.mp4" type="video/mp4" />
</video>

<a href="#" class="mpplay">play</a>
<a href="#" class="mppause">pause</a>
<a href="#" class="mptime">1:00</a>
<a href="#" class="mptime">0:30</a>

<script>

function convert(input) {
    var parts = input.split(':'),
        minutes = +parts[0],
        seconds = +parts[1];
    return (minutes * 60 + seconds).toFixed(2);
}

jQuery(document).ready(function($) {
    // declare object for video
    var player = new MediaElementPlayer('#player1');

     jQuery('.mpplay').click(function() {
        player.play();
     });

     jQuery('.mppause').click(function() {
        player.pause();
     });

     jQuery('.mptime').click(function() {
        var timeToGoVideo = "";
        timeToGoVideo = (this).text;
        timeToGoVideo = convert(timeToGoVideo);
        player.setCurrentTime(timeToGoVideo);
        player.setCurrentRail();
        player.play();
     });

});

</script>