Sonoport how to play audio (actionscript)

2019-06-08 12:40发布

There is manual http://sonoport.com/manual/ how to use as3 library to play audio with audio filters. I need tool AudioStretch but firstly try simple to play an audio external link.

What i do.

  1. I use mxmlc compiler, so includes SonoportCollection.swc
  2. Import com.sonoport.MP3PlayerSound;
  3. Try create and play

code:

mp3PlayerSnd = new MP3PlayerSound();
mp3PlayerSnd.audioFile = "http_url_link.mp3"; 
mp3PlayerSnd.play();

So, nothing play. I see that http get to server for link http_url_link.mp3 is sent ok. But there is no sound. What I do wrong?

Updated. I try test

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLRequest;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import com.sonoport.MP3PlayerSound;

    public class Pitcher extends Sprite {

        protected var trackSound:Sound;
        protected var trackChannel:SoundChannel;

        protected var _mp3_path:String;

        public function Pitcher():void {
            _mp3_path = 'http_path_to_audio_mp3';

            trackSound = new Sound();
            trackSound.load(new URLRequest(_mp3_path));
            trackChannel = trackSound.play();
        }
    }
}

This work fine! When I open .swf file in browser the music is playing

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLRequest;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import com.sonoport.MP3PlayerSound;

    public class Pitcher extends Sprite {

        protected var trackSound:Sound;
        protected var trackChannel:SoundChannel;

        protected var _mp3_path:String;

        public function Pitcher():void {
            var snd:MP3PlayerSound;
            snd = new MP3PlayerSound();
            snd.gain = 1;
            snd.audioFile = 'http_path_to_audio_mp3';
            snd.play();
        }

    }
}

This is not working. When I opened in browser .swf file I see that http request to the server for mp3 file is done but there is no music ...

I compile AS3 code with util mxmlc. Some like this command

"cd #{as3_path}; #{mxmlc} -include-libraries=SonoportCollection.swc -warnings=false -debug=false -static-link-runtime-shared-libraries=true -optimize=true -o #{swf_file} -file-specs #{as3_file}"

Maybe problem in my compiler command? ps. I'm not flash developer

1条回答
Juvenile、少年°
2楼-- · 2019-06-08 13:03

thanks Dima, can I just confirm that you're:

  • including the *.swc
  • importing the class

the code below works for me as a pure AS3 / Flash IDE project, feel free to upload a source link though if it doesn't work.

import com.sonoport.MP3PlayerSound;

var snd:MP3PlayerSound;
snd = new MP3PlayerSound();
snd.gain = 1;
snd.audioFile = "sound.mp3"; 
snd.play();

I believe the gain is defaults to 1, but I usually set it anyway.

查看更多
登录 后发表回答