在浏览器加载时设置Soundmanager2播放器位置

问题描述 投票:-3回答:1

我想在加载时设置Sound Manager Player的位置。例如,这里是URL:http://wp.simplepressplugins.com/sls247-what-content-you-should-be-using-for-2020/?t=300

if (isset($_GET['t']))
{
  $time = $_GET['t'];
  $params = array('time' => $time);
  wp_localize_script('timestamp-js', 'timestampget', $params);
}
jQuery(window).load(function($) {
  if (typeof timestampget !== 'undefined') {
    if (timestampget.time) {
      var time = timestampget.time;
      var soundurl = jQuery(".playercontent").find('.sm2-playlist-wrapper ul li a').attr('href');
      // using url converted to md5 hash so we can get it ... md5 function i already created a custom function
      var soundId = md5(soundurl);

      setTimeout(function() {
        window.soundManager.getSoundById(soundId).start();
        window.soundManager.getSoundById(soundId).setPosition(time * 1000);
      }, 500);

      setTimeout(function() {
        window.soundManager.getSoundById(Soundid).stop();
      }, 800);
    }
  }
});

当浏览器加载时,我想将播放器栏设置为t=300,即5分钟

enter image description here

它在Firefox中有效,但在Chrome或Safari(Mac)中无效。

[或者在任何情况下都可以检查setPosition是否完成并将小节移至准确的时间,然后我们可以停止播放器,或者我们可以不玩而只将小节移至给定的时间?

javascript jquery wordpress soundmanager2
1个回答
0
投票

不是使用外部JavaScript,而是尝试使用(SoundManager API)吗?这样做的方法很少,但是在这里,我选择了传递给play()方法的参数。在页面加载时调用此脚本以实现所需的内容。

var sound = soundManager.getSoundById('chinaCymbal');
sound.play({
  position: 30000 // 30 seconds into sound
});

或其他选项

var fhDemo = soundManager.createSound({
  url: 'http://freshly-ground.com/data/audio/sm2/fitter-happier-64kbps.mp3'
});

function playFrom(nFrom) {
  fhDemo.stop(); 
  fhDemo.play({
    from: nFrom
  });
}

jQuery(window).load(function{
  playFrom(30000);
});
© www.soinside.com 2019 - 2024. All rights reserved.