Mp3 and TimerEvent not in sync

Last night a buddy of mine who I make music with was asking
me if I could get objects to move in flash in sync with the sounds.
I said I might be able to, and figured it would be good to load an
mp3, a simple hihat called hihat.mp3. My idea is to set up a
TimerEvent that calls a function 'hitHiHat()' every 250
milliseconds. Problem is, when I run the program, the sound of the
mp3 is not in sync. I thought this might be a bad idea because the
TImerEvent might not be very accurate, but I remember reading
somewhere that the TimerEvent is VERY accurate. If it's not, I
definitely can't do what I'm trying to do, because the idea is to
have multiple instruments playing. If it's not the TimerEvent, I
thought that maybe it's the _sound.play() function that is lagging,
or that maybe there is a conflict with the mp3 already playing when
the hitHiHat function is called. Please let me know if I could do
something to make this program have a bit more rhythm, or if it's
just a bad idea altogether (code below). THANKS!
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.xml.*;
import flash.display.Loader;
import flash.filters.DropShadowFilter;
//import kurt.classes.Console;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
[SWF(backgroundColor="0x000000")]
public class gentlemansound extends Sprite {
private var tf:TextField = new TextField();
private var circle:Sprite;
private var tempo:Timer;
private var _sound:Sound;
private var urlReq:URLRequest;
private var soundChan:SoundChannel;
private var needsToPlay:Boolean;
public function gentlemansound() {
init();
private function init():void {
needsToPlay = true;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
circle = new Sprite();
circle.graphics.beginFill(0xFFFFFF);
circle.graphics.drawCircle(100,400,40);
circle.graphics.endFill();
addChild(circle);
_sound = new Sound();
urlReq = new URLRequest("sounds/hihat.mp3");
_sound.load(urlReq);
_sound.addEventListener(Event.COMPLETE, startHiHat);
tempo = new Timer(250);
tempo.addEventListener(TimerEvent.TIMER, hitHiHat);
tf.width = 400;
tf.height = 200;
tf.border = true;
tf.multiline = true;
tf.x = 10;
tf.y = 20;
//tf.x = stage.stageWidth / 20;
//tf.y = stage.stageHeight / 20;
tf.text = "blah blah blah blah blah blah blah blah blah blah
blah blah blah blah";
//addChild(tf);
private function startHiHat(event:Event):void {
tempo.start();
private function hitHiHat(event:TimerEvent):void {
if (needsToPlay == true) {
soundChan = _sound.play();
needsToPlay = false;
soundChan.stop();
soundChan = _sound.play();

the timer function (along with setInterval and every other
loop in flash) is inaccurate and very much dependent on local
system speed. in short, there is no loop in flash suitable for
synch'g sound and anything else. the ear it too sensitive to even
small mis-timings.
you can however, create a self-correcting loop based on
getTimer() (which is as accurate as the local system clock) which
can maintain a small error tolerance. even this, however, may not
be satisfactory for your purposes and you may need to synch sound
and animation in a flv.

Similar Messages

  • I just got an iPad 2 and have not yet synced to my computer. I don't want to have all the duplicate songs in my iTunes. How do I get rid of duplicates?

    I just got an iPad 2 and have not yet synced to my computer. I don't want to have all the duplicate songs in my iTunes. How do I get rid of duplicates?

    You don't say whether you are on PC or Mac. For Mac there are these two programs which might help (I havn't tried either) :
    http://www.apple.com/downloads/macosx/ipod_itunes/songsergeant.html
    http://www.apple.com/downloads/macosx/ipod_itunes/idupe.html
    There are probably similar programs for PCs, but I don't know what they are. On a PC you can hold the shift key and do File > Display Exact Duplicates (without the shift they may not be exact matches) - if one of each duplicate pair has the same date added then you can sort by that and then delete those with (or without) that date.

  • Audio and video not in sync. went back to previously finished projects and they too are not in sync. What could be the problem?

    Audio and video not in sync. Went back to previously edited projects and they too are now not in sync. What could be the problem?

    Um ... some useful data?
    OS/CPU/RAM/GPU/vRAM ... version of PrPro ... and other programs or plugi-ins/3rd-party apps involved ... footage type/codec/wrapper ... such things would be very useful.
    Neil

  • Video and audio not in sync

    Anybody else experiencing video & audio not in sync since upgrading to Lion? I have a MacBook Pro 15-inch, Early 2011 with
    AMD Radeon HD 6490M 256 MB graphics. I mostly stream You Tube, Netflix, & news videos and occasionally watch movies I have in iTunes or on DVD, and since upgrading, I've seen out of sync video and audio in every one of these situations. Sometimes it starts out OK and then slowly deteriorates. Other times it just starts out that way and stays that way. Happens with all browsers as well as iTunes and DVD Player. Tried a few Google searches but haven't come across any postings reporting this with Lion, so I thought I would try here. Thanks for any confirmations and/or pointers to a solution if there is one.

    Ahh...boom. I have it too. Forgot it was even there. I had it turned off back when running Snow Leopard since it was glitchy. Apparenty, I somehow reenabled it and wasn't even aware it was on since its volume was turned down. After disabling it, all video & audio appears to be in sync.
    boom...the sound you'll hear as I nuke it from my system.
    Thanks efrancis76 for figuring this out. Much appreciated!

  • Video and audio not in sync. Other answers here do not help.

    My audio and video are not in sync in many streams but some are OK.
    I do not have any extensions, add-ons and I am using the default theme. I have disabled hardware acceleration. I am now running in Safe Mode and the problem persists.
    The video and audio sync for the first few minutes and then they work their way futhter and further apart, usually several seconds out of sync. I don't think this particular situation has been covered in the other posts.

    You can check for problems with current Flash plugin versions and try these:
    *disable a possible RealPlayer Browser Record Plugin extension for Firefox and update the RealPlayer if installed
    *disable protected mode in the Flash plugin (Flash 11.3+ on Windows Vista and later)
    *disable hardware acceleration in the Flash plugin
    *http://kb.mozillazine.org/Flash#Troubleshooting

  • Video and audio not in sync (ALSA underrun occurred)

    Hi, after a recent system upgrade (upgrade log here http://pastebin.com/1gRwexFr), video and sound are not in sync anymore. The problem occurs in mplayer instantly, and in XBMC after a while (the audio is slowly getting out of sync). The error message I get continuously in XBMC is "ALSA lib pcm.c:7339:(snd_pcm_recover) underrun occurred". The error I get in mplayer is "[ac3 @ 0xf46b40]frame sync error" I did another system upgrade and the problem persists. I'm using Terratec Aureon 7.1 external sound card and linux 3.3.3-1-ARCH. I'm not using pulseaudio, just alsa.
    EDIT: I downgraded (sudo pacman -U linux-3.2.13-1-x86_64.pkg.tar.xz linux-headers-3.2.13-1-x86_64.pkg.tar.xz linux-api-headers-3.1.6-1-x86_64.pkg.tar.xz dbus-1.4.16-1-x86_64.pkg.tar.xz dbus-core-1.4.16-1-x86_64.pkg.tar.xz glibc-2.15-7-x86_64.pkg.tar.xz) and the problem seems to be gone. I'm suspecting the kernel upgrade broke it..
    Last edited by nawitus (2012-05-02 20:08:53)

    nawitus wrote:underrun occurred
    See what buffer size you end up with. Start mplayer, and run:
    cat /proc/asound/card0/pcm0p/sub0/hw_params

  • Audio and video not in sync? Also photos won't load?

    My video and audio are not in sync on photobooth for videos. Anyone know how to fix this!? Please
    Also, when I try to change my background on the desktop, when it is supposed to load the pictures for me to choose from it just freezes. It continues to say "loading images..." but they never show up. How do I fix this??

    Videos shot directly from my MacBook

  • Audio and Video not in Sync (Decklink a/v)

    Hello. No matter what I do, Soundtrack Pro's audio and video are not in sync. Audio always comes a slight bit later which makes working in STP really hard. I run STP with a Decklink Extreme, for both audio and video. Any tips?

    well i had the same post. kinda. but yeah it is totally limited as a film scoring app, who would have thought. there isn't any way to offset the sync.
    Logic would be your best bet, or Pro Tools with DV kit.
    FP

  • Audio through RCA and HDMI not in sync

    Hi,
    Is this a common problem?
    Recently got a tv with hdmi so the appletv is now connected with hdmi to the tv. But it is also still connected to my stereo though the rca connection (for music or movies with soundtracks that I really want to enjoy).
    Problem with both music and movies is that the audio is not in sync between hdmi and rca. Hdmi is a bit delayed.
    Now for music this is not that much of and issue as I usually have the tv off and use the iphone remote to select music on the appletv which plays then through the sereo. But for movies it is, I have to turn off the tv volume completely. It was much better to have the sound of the tv also on for dialogue, gave a more natural impression if it did not only come from the stereo. But with the delay it is just not good anymore.
    Any ideas, known problem? Fixable?
    Thanks,
    S.

    Stekke wrote:
    Hi,
    Is this a common problem?
    Recently got a tv with hdmi so the appletv is now connected with hdmi to the tv. But it is also still connected to my stereo though the rca connection (for music or movies with soundtracks that I really want to enjoy).
    Problem with both music and movies is that the audio is not in sync between hdmi and rca. Hdmi is a bit delayed.
    Any ideas, known problem? Fixable?
    Most modern TV's have an input lag during which various processing is applied to the video signal, and the TV audio will be delayed accordingly - the longer this delay the more you're likely to notice a discrepancy between RCA/optical and HDMI.
    This is not the AppleTV's problem.
    While you might want both audio outputs playing together it invariably causes problems.
    Only if your amp has some kind of delay function on the input could you compensate by slowing teh audio from the amp.

  • 5G iPod Audio and Video not in Sync

    I bought an iPod 30 GB a couple of days before. I was trying to download a movie to it which is in MP4 format. The original movie was in AVI format and I used Videora iPod converter to convert AVI -> MP4, but when I try to view the movie in my iPod the Audio and Video are not in Sync at al. The audio is way ahead of the video. Please someone let me know how to fix this problem. I turned off Equalizer and all other fancy settings in the iPod but it still didn't help.

    some encoders have this problem occasionally. I've seen it very frequently in ffmpex when the source is avi. not sure what you're using, but so I'd suggest you try a different software. I'm getting very good results out of handbrake or 42.

  • HT3209 sound and picture not in sync

    when i play a downloaded movie, the sound is not in sync with the scene. why is this happening and how do i fix it? i have tried shutting down and restarting my computer but that doesnt help

    Try (free) Quicktime Broadcaster and see if it improves the sync. Is it out of sync from the first second or after a long period of time?

  • Voice and picture not in sync

    I down loaded breaking dawn 1 a;nd 2 and the voice is not in sync with picture.

    Hey raymondgauthier,
    Thanks for using Apple Support Communities.
    Looks like you are having trouble with the playback performance unsing airplay. This article provides steps for troubleshooting performance issues.
    iTunes: Troubleshooting AirPlay and AirPlay Mirroring
    http://support.apple.com/kb/ts5209
    Have a nice day,
    Mario

  • Calendaro and Phone not in sync

    Gmail calendar and Droid X stopped syncing.  Gmail on my computer doesn't allow me to fix it.  I don't like to have to post it on the phone and then again on my Gmail account.  Any suggestions for this new user?

    Gmail calendar and Droid X stopped syncing.  Gmail on my computer doesn't allow me to fix it.  I don't like to have to post it on the phone and then again on my Gmail account.  Any suggestions for this new user?

  • Purchased, mp3 and Podcasts won't sync to 160 gig classic

    I have a six-month-old iPod Classic 160 gig, with about 90 gig of music and 10 gig of video on it. In the last two weeks, though, iTunes tells me that 109 tracks won't sync, with the error message "because they cannot be played on this iPod." Some of them, homegrown movies, I understand, but others are either podcasts downloaded through the iTunes store, purchased music (Sheryl Crow's new album) or recently ripped tracks that I did through iTunes using either 128 AAC or Apple Lossless. Most of the ones I've noticed to date were imported in the last 2-3 weeks, and play fine on iTunes, just not the iPod.
    I've tried restoring the iPod and deauthorizing then reauthorizing the computer. Neither works. The next step, I think, would be to rebuild my library, but I have tons of playlists I don't want to recreate (or export/import one-by-one, which is how it looks like have to do it).
    I can't help but wonder if this is something related to the latest updates to iTunes, seeing as how it's a such a new phenomenon, and there seem to be several similar posts (although not exactly my situation) in discussions.
    I welcome any and all suggestions!
    - Paul

    Paulza wrote:
    ... iTunes tells me that 109 tracks won't sync, with the error message "because they cannot be played on this iPod." Some of them ... are ... podcasts downloaded through the iTunes store
    Podcasts are completely independent of Apple and iTunes, they're not from iTunes itself. All iTunes does is list the podcast and tell iTunes where to go and find it if you ask to download it. There are other (non-iTunes) Podcast catchers which do the same thing for other MP3 players. So I think that when listing podcasts on iTunes, Apple/iTunes does not consider it's playablity - because it's a podcast and that's the way of Podcasts! Also, the podcaster has probably not produced these podcasts specifically for the iPod and so has not realised that they don't work on our iPods as you and I expect them to.
    You could try sending feedback to the podcast creator, explaining that their Podcasts don't play on the iPod itself. They may +_or may not_+ do something about it.
    I've had this problem with both audio and video Podcasts. There is an option to convert selections for the iPod which I have tried for the videos, (click on the top menu and *Advanced/Convert selection for iPod/iPhone*. However, this process takes forever and I gave up trying it. I simply watch them in iTunes. I cannot actually remember what I did for the audio Podcasts, but if I right-click (in Windows that is..) on an audio Podcast, I see the option to *convert selection to AAC*. I don't promise that it will work, but you could give it a try.
    As for the Sheryl Crow album , if it was purchased from iTunes, I would expect it to play on the iPod without converting it. The same goes for tracks ripped using iTunes on your PC. I can't explain that, perhaps someone else can?
    Regards,

  • IOS 6 disaster. Facetime and imessage not working. sync problems

    Hi all.
    I just wanted to know if anyone else  has experienced so many bugs with iOS6?
    Upgraded to an ipad 3 32GB  wifi . Gave my dad ipad 2(restored and logged in with his apple id).
    All was well. Then iOS 6 came along
    I am able to log into my apple id but everytime i try to sign into facetime it says username or password is incorrect.
    it worked a couple times but then stopped working again.
    I am positive the password is correct.
    I reset the password and am using the new one.
    It is correct.
    Restored the ipad.
    worked for a while.. then the same thing
    now i can't sync, Am getting an error message . Currently restoring the ipad again.
    I am able to purchase items on itunes still on my desktop and my apple id seems to be working otherwise.
    Facetime and imessage is not
    please help?
    anyone else experienced similiar issues with iOS6 ?
    It should be mentioned that i couldn't purchase items directly from my ipad with the appstore for a period of time but it worked when i purchased through itunes on my desktop
    Are these bugs associated with iOS6?
    Again any help will be greatly appreciated
    Cheers

    I have the exact same problem!! it's been driving me crazy!! I have iPhone 4 but my iMessage works fine however.
    Just the FaceTime doesn't work at all, my phone number is registered ,
    just when I try to add my email (apple ID) to make the facetime works & activate .. I write down my email & password correctly , it says password is incorrect! =(((
    I changed my password, I tried resetting the settings and turning on & off the phone and all. Nothing Works!!
    this is one of MANY bugs I have after I updated (& made the most terrible mistake of my life) to iOS 6 !!
    Apps are crashing & force closing including their new app store. Youtube application is vey slow. Maps aren't accurate not even half the quality of google maps. Screen freezes sometimes =((
    I'm very disaapointed at Apple seriously!! this could be their one mistake that will drop down their whole legendary iPhone into the sewer! 

Maybe you are looking for