te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - howler.js play sound at a specific position - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - howler.js play sound at a specific position - Stack Overflow

programmeradmin3浏览0评论

Hi I would like to start playing a sound on a scecific position. The api said that I can use .pos but it doesn't start where I would like it to start

  <p>This sound last 13 sec.</p>
  <h1>Audio</h1>
  <h3><a href="#" class="val2">2:00</a></h3>
  <h3><a href="#" class="val3">3:00</a></h3>
  <h3><a href="#" class="val4">4:00</a></h3>
  <h3><a href="#" class="val20">10:00</a></h3>

My javascript.

var son = [false, "0000"]

sound = new Howl({
    urls: ['.mp3'],
    autoplay: false
    });

function playSequence(events,valeur){

  //if there is no sound play the track at a certain position
  var playSound = function(valeur){
    if(son[0] == true){
      sound.stop();
      son[0] = false;
    }else{
      son[0] = true;
      sound.pos = parseInt(valeur[0]); // position at 2 sec
      sound.play();
    }
  }
   playSound(valeur);
}

//play the sound on click
$("a.val2").on('click', function(events){
    valeur = $(this).text();
    playSequence(events, valeur);
    });

Hi I would like to start playing a sound on a scecific position. The api said that I can use .pos but it doesn't start where I would like it to start

  <p>This sound last 13 sec.</p>
  <h1>Audio</h1>
  <h3><a href="#" class="val2">2:00</a></h3>
  <h3><a href="#" class="val3">3:00</a></h3>
  <h3><a href="#" class="val4">4:00</a></h3>
  <h3><a href="#" class="val20">10:00</a></h3>

My javascript.

var son = [false, "0000"]

sound = new Howl({
    urls: ['http://goldfirestudios./proj/howlerjs/sound.mp3'],
    autoplay: false
    });

function playSequence(events,valeur){

  //if there is no sound play the track at a certain position
  var playSound = function(valeur){
    if(son[0] == true){
      sound.stop();
      son[0] = false;
    }else{
      son[0] = true;
      sound.pos = parseInt(valeur[0]); // position at 2 sec
      sound.play();
    }
  }
   playSound(valeur);
}

//play the sound on click
$("a.val2").on('click', function(events){
    valeur = $(this).text();
    playSequence(events, valeur);
    });
Share Improve this question asked Nov 7, 2014 at 1:44 Papouche GuinslyzinhoPapouche Guinslyzinho 5,45814 gold badges64 silver badges106 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

pos is a method, not a property. For best patibility, you would want to play it like follows (fixed in the 2.0 beta branch):

sound.play(function(id){
    sound.pos(valeur[0], id);
});

Here's how you would do it in 2.0 (check 2.0 branch at https://github./goldfire/howler.js):

var id = sound.play();
sound.seek(valeur[0], id);

If you are only playing one sound then there is no need to set the id, but it is best practice to change the position after playing when using 1.1.x.

I was having issues playing a sound at a specific time as well, it worked on the first play of a sound, but if I tried to go back and play that sound again, using seek immediately wouldn't work.

I just figured out a way to consistently make it work using howler v2:

function playSoundAtPosition(sound, pos) {
  sound.once("play", () => {
    sound.seek(pos);
  });
  sound.play();
}

This makes use of the callback method once which fires the callback to the play event and then immediately removes itself. I believe this helps because it waits until it actually knows the sound is playing before seeking to the desired time.

I know this is an old question but hopefully it's useful to someone if they e across this!

You can use Sprites!

var sound = new Howl({
  src: ['sounds.webm', 'sounds.mp3'],
  sprite: {
    blast: [0, 3000],
    laser: [4000, 1000],
    winner: [6000, 5000]
  }
});

// Shoot the laser!
sound.play('laser');

:)

I found it at this link How to Create and use Sprites

发布评论

评论列表(0)

  1. 暂无评论