• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Control playhead location with sound array

Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

Hey Everyone,  Have some old AS2 that I need to transition over to AS3.  I am having trouble finding reference on how to convert the array portion of the AS2 code below.  We used this to control the playhead so we could bring things onto the screen times to certain parts of our audio. I have gotten my audio playing with the AS3 at the bottom of this message but can't seem to tie it into an array.  Any auggestions or things you can point me to?

//AS2

//placed on Frame 1

soundArray = new Array();

soundArray = [8,15,21,27,36];

trace(soundArray);

speech = new Sound(this);

//placed on Frame2

stopAllSounds();

counter = 0;

_root.sndPause = 0;

silent = false;

//set to true onSoundComplete

speech.loadSound("audio/1307_t2_p5.mp3", true);

speech.start();

//playMC.gotoAndStop(2);

speech.onSoundComplete = endLoop;

// This code was placed on Frames where I "held" the playhead until another array point was met

stop();

syncPoint = (soundArray[counter]*1000);

ID = setInterval(this, "isDone", 500);

//////////////////////////////////////////////////////////////////////////////

//AS3

import flash.events.Event;

import flash.media.Sound;

import flash.net.URLRequest;

var speech:Sound = new Sound();

speech.addEventListener(Event.COMPLETE, onSoundLoaded);

var req:URLRequest = new URLRequest("audio/993_m2_p6.mp3");

speech.load(req);

function onSoundLoaded(event:Event):void

{

    var localSound:Sound = event.target as Sound;

    localSound.play();

}

TOPICS
ActionScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

what's the isDone function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

Are you simply using the array as a timing mechanism and calling the isDone() function every 1/2 second to check? If so, just use a Timer in AS3 - the array stuff should be identical. Also, in your AS3 code, why are you making a new localSound variable within your onSoundLoaded? In there you can just call speech.play() - you already have a reference to it, why not use it. I'm not fully sure what you are doing, but if you are just wanting to do something at specific times then I think this should be useful:

var soundArray:Array = [8, 15, 21, 27, 36];

var counter:int = 0;

var syncTimer:Timer = new Timer(0, 1);

syncTimer.addEventListener(TimerEvent.TIMER, nextSync, false, 0, true);

var speech:Sound = new Sound();

speech.addEventListener(Event.COMPLETE, onSoundLoaded);

var req:URLRequest = new URLRequest("audio/993_m2_p6.mp3");

speech.load(req);

function onSoundLoaded(event:Event):void

{

   speech.play();

   counter = -1;

   waitForSync();  

}

function waitForSync():void

{

          syncTimer.reset();

          counter++

          if(counter == 0){

                    syncTimer.delay = soundArray[counter] * 1000;

          }else{

                    syncTimer.delay = (soundArray[counter] - soundArray[counter - 1]) * 1000;

          }

          syncTimer.start();

}

function nextSync(e:TimerEvent):void

{

          //do sync stuff here...

          trace("sync at:", soundArray[counter]);

          waitForSync();

}

Also, just to mention you can use Adobe Media Encoder to place cuepoints in the sound file and listen for those...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

I am just wanting to move the playhead at specific times during audio playback.  So for example as the audio plays I can display items in a bulleted list (without having to speread things out on the timeline)  or show and image at a certain time and so on.  That's where the SoundArray comes in "soundArray = [8,15,21,27,36];"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

OK, then I think this should work:

Frame 1 code:

var soundArray:Array = [8, 15, 21, 27, 36];

var counter:int = 0;

var syncTimer:Timer = new Timer(0, 1);

syncTimer.addEventListener(TimerEvent.TIMER, syncReady, false, 0, true);

var speech:Sound = new Sound();

speech.addEventListener(Event.COMPLETE, onSoundLoaded);

var req:URLRequest = new URLRequest("audio/993_m2_p6.mp3");

speech.load(req);

function onSoundLoaded(event:Event):void

{

   speech.play();

   counter = -1;

   waitForSync();  

}

function waitForSync():void

{

          syncTimer.reset();

          counter++

          if(counter == 0){

                    syncTimer.delay = soundArray[counter] * 1000;

          }else{

                    syncTimer.delay = (soundArray[counter] - soundArray[counter - 1]) * 1000;

          }

          syncTimer.start();

}

function syncReady(e:TimerEvent):void

{

          play();

}

Frames where you want to wait for the next sync:

stop();

waitForSync();

You'll need to add some error checking, but hopefully this gets you in the right direction.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

Thanks for the help.....I will give this code a look right now and see if I can get it to work.  I have heard about the Media Encoder option but I worry that with a lot of audio edits that we typiocally have that I would be adding work by adding the step of placing the cuepoints multiple times.  Changin a coupel array numbers seems easier. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

This woorked great, when the timer reached 8 seconds the timeline jumped to frame label "test". How would I add in the ability to do the same for the rest of the numbers in the array?

function nextSync(e:TimerEvent):void

{

          gotoAndStop("test");

          trace("sync at:", soundArray[counter]);

          waitForSync();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

OK, I think this should work:

Frame 1 code:

var soundArray:Array = [[8,"test"], [15,"pete"], [21,"test"], [27,"pete"], [36,"test"]];

var counter:int = 0;

var syncTimer:Timer = new Timer(0, 1);

syncTimer.addEventListener(TimerEvent.TIMER, syncReady, false, 0, true);

var speech:Sound = new Sound();

speech.addEventListener(Event.COMPLETE, onSoundLoaded);

var req:URLRequest = new URLRequest("audio/993_m2_p6.mp3");

speech.load(req);

function onSoundLoaded(event:Event):void

{

   speech.play();

   counter = -1;

   waitForSync();  

}

function waitForSync():void

{

          syncTimer.reset();

          counter++

          if(counter == 0){

                    syncTimer.delay = soundArray[counter][0] * 1000;

          }else{

                    syncTimer.delay = (soundArray[counter][0] - soundArray[counter - 1][0]) * 1000;

          }

 

          syncTimer.start();

}

function syncReady(e:TimerEvent):void

{

          gotoAndStop(soundArray[counter][1]);

          //play();

}

All I did was use a 2D array and add the frame labels as part of the timing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

It goes to the first Frame label but will not move to the second and beyond.  Really appreciate the help on this!!! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

Hmm, I tested with two frames and it moved between them fine... Did you use the newest code on frame 1, and then the two lines on subsequent frames? Have a small example I can look at?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

sorry, which two lines do I use on subsequent lines? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

Not sure how I messed up.  This is what I have on the First Frame of my movie.  Is part of this code suppose to be on all of the individual Frames I am jumping to?  I tried portions of it but when I do I get a "duplicate funtion" message. 

var soundArray:Array = [[4,"test1"], [6,"test2"], [8,"test3"], [10,"test4"], [12,"test5"]];

var counter:int = 0;

var syncTimer:Timer = new Timer(0, 1);

syncTimer.addEventListener(TimerEvent.TIMER, syncReady, false, 0, true);

var speech:Sound = new Sound();

speech.addEventListener(Event.COMPLETE, onSoundLoaded);

var req:URLRequest = new URLRequest("audio/993_m2_p6.mp3");

speech.load(req);

// I tried this portion below on the individual Frames

function onSoundLoaded(event:Event):void

{

   speech.play();

   counter = -1;

   waitForSync(); 

}

function waitForSync():void

{

          syncTimer.reset();

          counter++

          if(counter == 0){

                    syncTimer.delay = soundArray[counter][0] * 1000;

          }else{

                    syncTimer.delay = (soundArray[counter][0] - soundArray[counter - 1][0]) * 1000;

          }

           syncTimer.start();

}

function syncReady(e:TimerEvent):void

{

          gotoAndStop(soundArray[counter][1]);

          //play();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

GOT IT!  I missed part of your ealier message with

stop();

waitForSync();"

Thank you VERY much for the help!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 01, 2014 Mar 01, 2014

Copy link to clipboard

Copied

LATEST

I was away from my desk, and didn't see this till just now. Glad you got it worked out!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2014 Feb 28, 2014

Copy link to clipboard

Copied

dang....forgot to include the "isDone" portion.  It's sit on Frame 2 after "speech.onSoundComplete = endLoop;"

function isDone() {

    if (speech.position>syncPoint) {

        clearInterval(ID);

        counter++;

        play();

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines