Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6547451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:49:56+00:00 2026-05-25T11:49:56+00:00

I am using 2 sound channels to play 2 separate, externally loaded mp3 files

  • 0

I am using 2 sound channels to play 2 separate, externally loaded mp3 files at the same time. Right now I have the play button tied to a function that starts the first mp3, then the 2nd. The problem is – the 2nd mp3 starts a few milliseconds after the first. Is there a way that I can make sure these 2 start playing at the exact same time?

function playMusic(evt:MouseEvent):void
{

    channel = myMusic.play(songPosition);
    channel2 = myMusic2.play(songPosition);
    myTimer.start();
    btnPlay.mouseEnabled = false;
}

Edit: I found a clumsy workaround that matches the TIMER for the 2 audio sources. It works, but now I have a hiccup at the beginning while i tries to match:

    function updateTime(evt:TimerEvent):void
    {
        lblSongTime.text = convertTime(channel.position);
        if(channel.position!=channel2.position){   
 trace("out of sync")                
 SoundMixer.stopAll()
    channel = myMusic.play();
    channel2 = myMusic2.play(channel.position);

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:49:57+00:00Added an answer on May 25, 2026 at 11:49 am

    If you’re targeting flash player 10+, then you can use the sampleData event and extract method of the sound class to combine the two sounds.

    Basically, you’ll want to make a Sound subclass that handles the sampleData event by passing the position to the extract method of each of the two sounds you want to play. Then, you’ll combine the two ByteArrays and insert that into the event’s data member.

    The main thing to be careful about is that you can only give a maximum of 8k of data (if I remember correctly) to the sampleData event at a time. You’ll also probably want to average the two sounds, or at least reduce the volume when combining the sounds.

    It’s been a little while since I’ve written actionscript, so it’d take me a little time to write up some code for you, but if you still need help, let me know and I’ll try to give you more info or some code.

    EDIT

    Here’s a minimal class that’ll do what you want. You should add error checking and you may need to add stuff to handle sound transforms (e.g. volume adjustment) as using the sample data event may ignore a sound transform you apply at play (I don’t remember, but it shouldn’t be too hard for you to figure that out ^_^)…

    import flash.events.SampleDataEvent;
    import flash.media.Sound;
    import flash.utils.ByteArray;
    
    public class DualSound extends Sound {
        private var sa:Sound;
        private var sb:Sound;
    
        public function DualSound(a:Sound, b:Sound) {
            super();
    
            sa = a;
            sb = b;
    
            addEventListener(SampleDataEvent.SAMPLE_DATA, handleSampleData);
        }
    
        private function handleSampleData(e:SampleDataEvent):void {
            var ba:ByteArray, bb:ByteArray;
    
            ba = new ByteArray();
            bb = new ByteArray();
    
            sa.extract(ba, 8 << 10, e.position);
            sb.extract(bb, 8 << 10, e.position);
            ba.position = 0;
            bb.position = 0;
    
            while(ba.bytesAvailable > 0 && bb.bytesAvailable > 0) {
                e.data.writeFloat((ba.readFloat() + bb.readFloat()) / 2);
            }
            if(ba.bytesAvailable > 0) {
                e.data.writeBytes(ba, ba.position, ba.bytesAvailable);
            } else if(bb.bytesAvailable > 0) {
                e.data.writeBytes(bb, bb.position, bb.bytesAvailable);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play a sound based on which button is pressed using AVAudioPlayer.
Using ONE Sound() object in Actionscript3, how can I play a one MP3 and
How can I play an mp3 or wav sound using the jquery click event?
I am playing a background sound using the AVAudioPlayer Framework. I have a play
I'm trying to play only part of a sound using FMOD, say frames 50000-100000
I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I'm using AVAudioPlayer to play sound effects in an iPhone game. This is part
I'd like to play a synthesised sound in an iPhone. Instead of using a
I'm trying to play sound files (.wav) with pygame but when I start it
I am using Java JMF to play a MPEG video with sound. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.