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

发布于 2024-12-07 11:20:53 字数 814 浏览 2 评论 0原文

我有语音文本录音,我希望允许用户在录音中的特定点开始录音,例如开始时间后 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>

I have recordings of spoken text where I would like to allow users to start an audio recording at a specific point within the recording, for example, 12.5 seconds after the start time. Using the sample code below, how can I make this happen?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离鸿 2024-12-14 11:20:53

查找 mediaelementplayer 对象:

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

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

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

:)

Find mediaelementplayer object:

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

Set time in seconds (12.5 for example):

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

:)

岛徒 2024-12-14 11:20:53

我能够弄清楚如何通过外部链接控制 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>

I was able to figure out how to control the mediaelement.js player with external links. The player has to be initialized using a variable.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文