驻波:无限循环 MP3

发布于 2024-12-01 11:21:07 字数 394 浏览 0 评论 0原文

如何在 驻波 中无限循环播放 mp3 文件。我尝试过 LoopSource 和 SoundGenerators 等,但我没有运气。我在文档或网上找不到循环 anInfinitely mp3 的人的使用示例:

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

谢谢

How do I infinitely loop an mp3 file in standing wave. I've tried LoopSource with SoundGenerators etc, but I've had no luck. I can find no usage examples in the documentation or online of someone looping anInfinitely mp3:

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

Thanks

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

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

发布评论

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

评论(4

年华零落成诗 2024-12-08 11:21:07

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

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

希望有帮助。

I am the lib's author. Since a lot of people ask this question, I've added a page answering this question in the github wiki for the project.

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

Hope that helps.

反目相谮 2024-12-08 11:21:07

看起来 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)

it appears that the LoopSource function's AudioDescriptor parameter should match the soundGenerator parameter. according to the docs instantiating a new AudioDescriptor will set the channels and rate properties as NaN (even though they're typed at uint??). anyway, see if this works instead:

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

other than that, the AudioPlayer class contains a complete event, which is dispatched when the audio source has finished playing. you could simply set up your own loop using a boolean switch to call play(source:IAudioSource) from the complete handler.

雄赳赳气昂昂 2024-12-08 11:21:07

我一直在尝试使用如何使用loopsource信息这里< /a>.我可以播放声音,但只能循环 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 );

}

I have been trying to use the How-to-use-loopsource info here. I am able to play my sound, but it only loops 3 times. Thoughts?

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

}
何其悲哀 2024-12-08 11:21:07

好吧,由于我在尝试根据文档和少量在线帮助循环音频源时遇到了困难,所以我决定创建自己的 Standing Wave 3 插件库。它并不完美,但它可以完成工作,并且是在字节级别上;没有循环计时器或任何东西。它的工作原理是接收带有开始和结束循环点的声音。然后,它根据提供的时间(以秒为单位)多次克隆循环样本。它应该可以直接使用。这是 Main.as 类的代码
“examples”文件夹中的“looping”文件:

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/standwave3-addons

OK, since I was having a hell of a time trying to loop an audio source based on the documentation and a thin amount of help online, I decided to create my own Standing Wave 3 addons library. It's not perfect but it gets the job done, and on the byte level for that matter; No loop timers or anything. It works by taking in a Sound with beginning and ending loop points. Then it clones the loop sample a bunch of times based on the time provided in seconds. It should be straight forward to use. This is the code for the Main.as class in the
"looping" file in the "examples" folder:

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.

        }

    }

}

Check out the source files over here:
https://github.com/charlesclements/standingwave3-addons

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