[Laszlo-checkins] r11323 - in openlaszlo/trunk/WEB-INF/lps/lfc/kernel: swf swf9
max@openlaszlo.org
max at openlaszlo.org
Thu Oct 2 11:32:18 PDT 2008
Author: max
Date: 2008-10-02 11:32:16 -0700 (Thu, 02 Oct 2008)
New Revision: 11323
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
Log:
Change 20081002-maxcarlson-6 by maxcarlson at Bank on 2008-10-02 10:52:11 PDT
in /Users/maxcarlson/openlaszlo/trunk-clean
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: UPDATED: Make streaming mp3 audio act more like a movieclip
Bugs Fixed: LPP-7051 - SWF8/9: Small Apps: Music demo cannot be replayed
Technical Reviewer: andre.bargull at udo.edu
QA Reviewer: promanik
Documentation: Streaming mp3 audio will now start over at the beginning after the end of the clip has been reached, unless play() is passed a specific value.
Details: LzSoundMC.as - Start at the beginning if we're not seeking to a specific frame and we're at the end already. Pass a flag from gotoAndPlay() to play() so we know when to auto seek.
LzSprite.as - Track totalframes in the sprite. Start at the beginning if we're not seeking to a specific frame and we're at the end already. Don't allow seeking past the end. Set frame = totalframes in soundCompleteHandler to avoid ms -> frame number roundoff errors.
Tests: See LPP-7051. Also fixes seeking past the end in swf9.
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as 2008-10-02 17:54:30 UTC (rev 11322)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzSoundMC.as 2008-10-02 18:32:16 UTC (rev 11323)
@@ -29,11 +29,16 @@
SoundMC.prototype.loadstate = 0;
/**
- * @access private
+ * @access private
*/
-SoundMC.prototype.play = function() {
- var t = this._currentframe / this._fps;
- if (t < 0) t = 0;
+SoundMC.prototype.play = function(direct=false) {
+ // if we're not seeking to a specific frame and we're at the end already, start at the beginning
+ if (direct != true && this._currentframe == this._totalframes) {
+ t = 0;
+ } else {
+ var t = this._currentframe / this._fps;
+ if (t < 0) t = 0;
+ }
this._sound.stop();
this._sound.start(t)
//Debug.write('play mp3', t);
@@ -46,7 +51,7 @@
*/
SoundMC.prototype.gotoAndPlay = function(f) {
this._currentframe = f;
- this.play();
+ this.play(true);
}
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-10-02 17:54:30 UTC (rev 11322)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-10-02 18:32:16 UTC (rev 11323)
@@ -43,6 +43,7 @@
public var clickregion:Shape = null;
public var masksprite:Sprite = null;
public var frame:int = 1;
+ public var totalframes:int = 1;
public var frames:int = 1;
public var resource:String = null;
public var source:String = null;
@@ -198,7 +199,8 @@
this.resourcewidth = res.width;
this.resourceheight = res.height;
if (this.owner != null) {
- this.owner.resourceevent('totalframes', res.frames.length);
+ this.totalframes = res.frames.length;
+ this.owner.resourceevent('totalframes', this.totalframes);
}
if (imgLoader) {
this.unload();
@@ -222,7 +224,7 @@
this.resource = r;
this.sound = new res['assetclass']() as Sound;
- this.owner.resourceevent('totalframes', Math.floor(this.sound.length * 0.001 * MP3_FPS));
+ this.updateTotalframes();
// TODO: add condition on this
this.startPlay()
@@ -439,7 +441,8 @@
if (framenumber != null) {
framenumber += rel ? fr : 0;
} else {
- framenumber = fr;
+ // start at the beginning again if we're already at the end.
+ framenumber = fr >= this.totalframes ? 0 : fr;
}
if (play) {
@@ -461,7 +464,7 @@
} else if (event.type == Event.COMPLETE) {
this.soundLoading = false;
this.owner.resourceevent('loadratio', 1);
- this.owner.resourceevent('totalframes', Math.floor(this.sound.length * 0.001 * MP3_FPS));
+ this.updateTotalframes();
// send events, including onload
this.sendResourceLoad();
@@ -484,13 +487,21 @@
/**
* Track playback
*/
- private function soundFrameHandler (event:Event = null) :void {
+ private function soundFrameHandler (event:Event) :void {
// Event.ENTER_FRAME
var fr:Number = Math.floor(this.soundChannel.position * 0.001 * MP3_FPS);
this.frame = fr;
this.owner.resourceevent('frame', fr);
- var tfr:Number = Math.floor(this.sound.length * 0.001 * MP3_FPS);
+ this.updateTotalframes();
+ }
+
+ /**
+ * update totalframes for audio
+ */
+ private function updateTotalframes () :void {
+ var tfr:Number = Math.floor(this.getTotalTime() * MP3_FPS);
+ this.totalframes = tfr;
this.owner.resourceevent('totalframes', tfr);
}
@@ -500,8 +511,9 @@
private function soundCompleteHandler (event:Event) :void {
// Event.SOUND_COMPLETE
if (this.playing) {
- // call manually to update 'frame'
- this.soundFrameHandler();
+ this.frame = this.totalframes;
+ this.owner.resourceevent('frame', this.frame);
+
// SoundChannel.position does not stop exactly at Sound.length,
// there are a few ms difference between both values.
// So instead of comparing 'frame' == 'totalframes',
@@ -1275,6 +1287,9 @@
function seek (secs:Number, doplay:Boolean) :void {
if (this.isaudio) {
var pos:Number = Math.max(this.getCurrentTime() + secs, 0);
+ // don't seek too far
+ if (pos > this.getTotalTime()) pos = this.getTotalTime();
+
if (this.playing) {
this.stopPlay();
}
More information about the Laszlo-checkins
mailing list