Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用SoundManager播放MP3几秒钟2_Javascript_Mp3_Soundmanager2 - Fatal编程技术网

Javascript 使用SoundManager播放MP3几秒钟2

Javascript 使用SoundManager播放MP3几秒钟2,javascript,mp3,soundmanager2,Javascript,Mp3,Soundmanager2,有没有办法识别出几秒钟内可以播放的所有歌曲 <a href="songs/1.mp3" class="sm2_button"> </ a> 我已初始化SoundManager 2 soundManager.setup ({ url: 'stockings /', preferFlash: true, onReady: function () { console.log ('SM2 Ok!'); } }); 我的mp3文件

有没有办法识别出几秒钟内可以播放的所有歌曲

<a href="songs/1.mp3" class="sm2_button"> </ a>
我已初始化SoundManager 2

soundManager.setup ({
    url: 'stockings /',
    preferFlash: true,
    onReady: function () {
        console.log ('SM2 Ok!');
    }
});
我的mp3文件和sm2_按钮类,总共大约有10个文件,我希望每个人都能播放几秒钟

<a href="songs/1.mp3" class="sm2_button"> </ a>


我希望你能帮我一把。

哎呀,我玩了一会儿。谢谢你提出这个有趣的问题。这将在DOM中使用jQuery查找mp3文件列表,并创建通过单击开始按钮播放的播放列表

<script>
var playList = new Array();

$(document).ready(function() {
    var soundFileList = new Array();
    $('ol#list2 li a').each(function() { // find soundfiles in <li><a data='*'>
        $('ol#list2 li a').css('color','#000');
        soundFileList.push( this.getAttribute('data') );
    });
    var newpl = { // create a selfmade playList object
        nextSongNumber: 0, // track number with which the player starts
        playLength: 7012,  // milliseconds to play each track
        idScheme: 'pl2_',  // a given scheme as 'soundID+songNumber'
        songUrl: './',     // url where your files are
        songList: soundFileList,
        fadeIn: 2000,      // fadeIn in milliseconds
        fadeOut: 1000      // fadeOut in milliseconds
    }
    playList.push( newpl ); // push it to our preset playlist
    $('#startbutton').on('click',function(){
        // call list 0 in playList[]
        playThisPlayList( 0, playList);
    });
});

soundManager.setup({
  url: './soundmanager2/swf/',
  // preferFlash: false,
  //flashPollingInterval: 4 , //in ms, overrules useFastPolling & useHighPerformance
  useFastPolling: true,
  useHighPerformance: true,
  onready: function() {

    function SkipThruPlayList( pl ) {
      if ( pl.nextSongNumber+1 > pl.songList.length ) {
          //will be called after the last song in playList
          pl.nextSongNumber=0; //needed for replay the playList
          return;
      } else {
        if(songObject){ songObject.destruct(); }
        var songObject = soundManager.createSound({
          id:  pl.idScheme + pl.nextSongNumber,
          url: pl.songUrl + pl.songList[ pl.nextSongNumber ],
          multishot: false
        });

        songObject.play({
          from: 0,
          to: pl.playLength,
          stream: true,
          autoPlay: false, //true if starting with pageload
          onplay: function() {
            $('ol#list2 li:nth-child('+pl.nextSongNumber+') a').css('color','#f00');
            //console.log('now play:',this.url, 'songid:',this.id, 'laptime:', this.duration);
          },
          onstop: function() {
            //console.log('songid:',this.id, ', songend was at:',this.position);
            // check your console, songend-positions are not stable values
            this.destruct(); //free memory from old song, necessary?
            SkipThruPlayList( pl ); // start over, create & play next songObject
          },
          whileplaying: function(){
            //this is a fadeIn / fadeOut mechanism
            var now=this.position;
            var mainVolume = 100; //we could set this up with playList
            if (now <= pl.fadeIn) {
                //fadeIn
                this.setVolume(parseInt((now/pl.fadeIn)*mainVolume));
            } else if (now >= (pl.playLength-pl.fadeOut)) {
                //fadeOut
                this.setVolume(parseInt(((pl.playLength-now)/pl.fadeOut)*mainVolume));
            } else {
                //play normal Volume between fadeIn and fadeOut
                this.setVolume(mainVolume);
            }
          }
        });
        pl.nextSongNumber++;
      }
    }

    function playThisPlayList( i, playList ) {
      var count= playList[i].songList.length;
      if (count > 0) {
        //console.log('we have:',count,' songs to play');
        SkipThruPlayList( playList[i] );
      } else {
        //console.log('no songs in this songlist');
        return;
      };
    }
    //playThisPlayList( 0, playList );
    window.playThisPlayList = playThisPlayList; //Broadcast function into BOM
  }
});

</script>

<button id="startbutton">start</button>
<ol id="list2">
  <li><a href="#" data="./test0.mp3">test0.mp3</a></li>
  <li><a href="#" data="./test1.mp3">test1.mp3</a></li>
  <li><a href="#" data="./test2.mp3">test2.mp3</a></li>
</ol>

var playList=新数组();
$(文档).ready(函数(){
var soundFileList=新数组();
$('ol#list2 li a')。每个(函数(){//find soundfile in
  • 还有更聪明的方法,但这是可行的。 例如,如果一条轨迹短于4096ms,会发生什么情况,也许您应该检查一下。 希望这有帮助


    来自柏林的问候

    谢谢你的创意。最后触摸一点由API文档支持的文件代码mp3-player-button.js,并添加几行soundmanager2

    行中:

    thisSound.play ();
    
    加:

    秘鲁的问候