Skip to content

Commit

Permalink
avm1: Sound.position and duration are not version-gated
Browse files Browse the repository at this point in the history
Even though they were added in SWFv6, they will be available when
playing a v5 SWF in Flash Player 6 and higher.

See #340 for an example in the wild.
  • Loading branch information
Herschel committed Oct 17, 2021
1 parent 04d84a3 commit 6034b4a
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions core/src/avm1/globals/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ fn duration<'gc>(
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if activation.swf_version() >= 6 {
if let Some(sound_object) = this.as_sound_object() {
return Ok(sound_object
.duration()
.map_or(Value::Undefined, |d| d.into()));
} else {
avm_warn!(activation, "Sound.duration: this is not a Sound");
}
// TODO: Sound.duration was only added in SWFv6, but it is not version gated.
// Return undefined for player <6 if we ever add player version emulation.
if let Some(sound_object) = this.as_sound_object() {
return Ok(sound_object
.duration()
.map_or(Value::Undefined, |d| d.into()));
} else {
avm_warn!(activation, "Sound.duration: this is not a Sound");
}

Ok(Value::Undefined)
}

Expand Down Expand Up @@ -253,17 +252,14 @@ fn position<'gc>(
this: Object<'gc>,
_args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
if activation.swf_version() >= 6 {
if let Some(sound_object) = this.as_sound_object() {
// TODO: The position is "sticky"; even if the sound is no longer playing, it should return
// the previous valid position.
// Needs some audio backend work for this.
if sound_object.sound().is_some() {
return Ok(sound_object.position().into());
}
} else {
avm_warn!(activation, "Sound.position: this is not a Sound");
// TODO: Sound.position was only added in SWFv6, but it is not version gated.
// Return undefined for player <6 if we ever add player version emulation.
if let Some(sound_object) = this.as_sound_object() {
if sound_object.sound().is_some() {
return Ok(sound_object.position().into());
}
} else {
avm_warn!(activation, "Sound.position: this is not a Sound");
}
Ok(Value::Undefined)
}
Expand Down

0 comments on commit 6034b4a

Please sign in to comment.