驻波:无限循环播放MP3

时间:2011-08-26 13:11:01

标签: actionscript-3 audio

如何在standing wave中无限循环播放mp3文件。我已经尝试过使用SoundGenerators等的LoopSource,但我没有运气。我在文档或网络上找不到循环无限mp3的人的例子:

var player:AudioPlayer = new AudioPlayer()
const generator:SoundGenerator = new SoundGenerator(sound)
source = new LoopSource(new AudioDescriptor(), generator)
player.play(source)

由于

4 个答案:

答案 0 :(得分:1)

我是lib的作者。由于很多人都在问这个问题,我在github wiki中为项目添加了一个回答这个问题的页面。

https://github.com/maxl0rd/standingwave3/wiki/How-to-use-loopsource

希望有所帮助。

答案 1 :(得分:0)

似乎LoopSource函数的AudioDescriptor参数应与soundGenerator参数匹配。根据实例化新AudioDescriptor的文档,将channelsrate属性设置为NaN(即使它们在uint处键入?)。无论如何,看看这是否有效:

var player:AudioPlayer = new AudioPlayer()
const generator:SoundGenerator = new SoundGenerator(sound)
source = new LoopSource(generator.descriptor, generator)
player.play(source)

除此之外,AudioPlayer类包含一个完整的事件,在音频源播放完毕后调度。您可以使用布尔开关设置自己的循环,以从完整的处理程序中调用play(source:IAudioSource)

答案 2 :(得分:0)

我一直在尝试使用How-to-use-loopsource信息here。我可以播放我的声音,但它只循环3次。想法?

import com.noteflight.standingwave3.performance.ListPerformance;
import com.noteflight.standingwave3.elements.AudioDescriptor;
import com.noteflight.standingwave3.performance.AudioPerformer;
import com.noteflight.standingwave3.elements.IAudioSource;
import com.noteflight.standingwave3.sources.SineSource;
import com.noteflight.standingwave3.output.AudioPlayer;
import hype.framework.behavior.AbstractBehavior;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.MP3Loader;
import com.noteflight.standingwave3.sources.LoopSource;
import com.noteflight.standingwave3.elements.Sample;
import flash.media.Sound;
import com.greensock.events.LoaderEvent;
import com.demonsters.debugger.MonsterDebugger;
import flash.events.Event;


var player:AudioPlayer = new AudioPlayer();
var loader:LoaderMax = new LoaderMax( { onComplete:onComplete } );
loader.append( new MP3Loader( "../deploy/assets/audio/Letter_A1.mp3", { autoPlay:false } ) );
loader.load();


function onComplete(e:LoaderEvent):void
{

    var mySound:Sound = e.currentTarget.content[ 0 ] as Sound;
    var length:Number = mySound.length * 44.1;
    var mySample:com.noteflight.standingwave3.elements.Sample = new com.noteflight.standingwave3.elements.Sample( new AudioDescriptor, length );

    mySample.extractSound( mySound, 0, length ); // now all of the Sound's data is in this Sample

    // LoopSource
    var myLoop:LoopSource = new LoopSource( new AudioDescriptor( 44100, 2 ), mySample );
    myLoop.firstFrame = 1;
    myLoop.startFrame = 1;
    myLoop.endFrame = myLoop.frameCount;

    // Play.
    player.play( myLoop );

}

答案 3 :(得分:0)

好吧,因为我有一段时间试图根据文档循环音频源并在线提供大量帮助,所以我决定创建自己的Standing Wave 3插件库。它并不完美,但它可以完成工作,并且在字节级别上完成;没有循环定时器或任何东西。它通过带有开始和结束循环点的声音来工作。然后它根据秒提供的时间克隆循环样本一堆。它应该是直接使用。这是Main.as类的代码 "循环"文件在"示例"文件夹:

package
{

    // Imports.
    import com.greensock.events.LoaderEvent;
    import com.greensock.loading.LoaderMax;
    import com.greensock.loading.MP3Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import com.greensock.TweenMax;
    import com.SW3.gadget.LoopGadget;
    import flash.media.Sound;


    // Class.
    public class Main extends Sprite
    {

        // Vars.
        private var loader:LoaderMax;// Using LoaderMax for ease of use.


        // Constructor.
        public function Main()
        {

            trace("Main");

            loader = new LoaderMax( { name:"audio", onComplete:onSoundsLoaded } );
            loader.append( new MP3Loader( "assets/Beat.mp3", { autoPlay:false } ) );
            loader.append( new MP3Loader( "assets/Clap.mp3", { autoPlay:false } ) );
            loader.append( new MP3Loader( "assets/Boom.mp3", { autoPlay:false } ) );
            loader.load();

        }


        private function onSoundsLoaded(e:LoaderEvent):void
        {

            trace("onSoundsLoaded");
            var looping:LoopGadget = new LoopGadget;
            looping.addLoopSound( "Beat", e.currentTarget.content[ 0 ] as Sound, 0, 10 );
            looping.addLoopSound( "Clap", e.currentTarget.content[ 1 ] as Sound, 0, 10 );
            //looping.addLoopSound( "Boom", e.currentTarget.content[ 2 ] as Sound, 0, 10 ); // Commented out to test possible error.

            looping.playLoop( "Beat" );// Play the "Beat" loop.
            looping.playLoop( "Clap" );// Play the "Clap" loop.
            looping.stopLoop( "Beat" );// Stop the "Beat" loop.
            looping.playLoop( "Beat" );// Play the "Beat" loop.
            looping.playLoop( "Beat" );// Play the "Beat" loop again to test if it would error out..

            looping.stopAllLoops();// Stop all the loops.
            looping.playLoops( [ "Beat", "Clap", "Boom" ] );// Play all the loops. Test to see if "Boom" will error out.

        }

    }

}

在这里查看源文件: https://github.com/charlesclements/standingwave3-addons