Simply put, I am making a flash midi player. I am using ENTER_FRAME for my timings. I set the framerate to 1开发者_StackOverflow00 to ensure that the timing of each note in milliseconds is accurate.
When I test the movie with CTRL + ENTER it works fine. When I publish it and open it in a browser (tested both IE and Chrome), it suddenly plays back a lot slower. I don't think it's a performance issue, since the code is very simple.
If this slowdown is consistent then I can perhaps work with it so that the playback speed will be correct. Do browsers make the framerate slower or do they implement a framerate cap of some sort? What is going on?
As far as I know, browsers DO implement a frame rate cap for Flash and other plugins in order to limit CPU usage.
You can run Mr.Doob's Stats class to find out the exact frame rate per second (mrdoob.com/blog/post/582).
For your midi player, If you are using sound on the timeline, if you need it to sync it's better to set the sound to the type, "stream" and deal with the lower sound quality if you are experiencing a gap before playback.
If it's not on the timeline, but you are instead loading sound externally, you can use a tool like Firebug to see how long it's taking for your sound file to buffer or load.
First off, and this is a big caveat, there's more or less no way of doing proper timing in flash. This is because you're almost always running your code in the UI thread. The UI thread is responsible for rendering the frames which may take a while for complex frames, making the frame rate actually go down. There are many reasons why the flash player might render less frames in certain conditions however. For instance, many browsers tend to dedicate less resources to flash player instances (and other plugins) that are in an inactive tab or in a minimized window. I don't know of any browser that deliberately makes flash slower in an active tab/window however. This article may provide more information.
Now, to address your actual problem. I'd suggest that you check your embed code in the html, there's probably a different value of the frame rate set there that might interfere with what you've set in your movie. That's why it's performing as expected in the standalone player but not when embedded.
精彩评论