diff --git a/core/src/avm2/globals/flash/media/soundchannel.rs b/core/src/avm2/globals/flash/media/soundchannel.rs index 2557e144d..848bba898 100644 --- a/core/src/avm2/globals/flash/media/soundchannel.rs +++ b/core/src/avm2/globals/flash/media/soundchannel.rs @@ -98,6 +98,19 @@ pub fn set_sound_transform<'gc>( Ok(Value::Undefined) } +/// Impl `SoundChannel.stop` +pub fn stop<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(instance) = this.and_then(|this| this.as_sound_instance()) { + activation.context.stop_sound(instance); + } + + Ok(Value::Undefined) +} + /// Construct `SoundChannel`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -129,5 +142,8 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> ]; write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES); + const PUBLIC_INSTANCE_METHODS: &[(&str, NativeMethodImpl)] = &[("stop", stop)]; + write.define_public_builtin_instance_methods(mc, PUBLIC_INSTANCE_METHODS); + class } diff --git a/tests/tests/regression_tests.rs b/tests/tests/regression_tests.rs index ce4bc8e22..9d986a1ec 100644 --- a/tests/tests/regression_tests.rs +++ b/tests/tests/regression_tests.rs @@ -661,6 +661,7 @@ swf_tests! { (as3_sound_play, "avm2/sound_play", 1), #[ignore] (as3_soundchannel_position, "avm2/soundchannel_position", 75), (as3_soundchannel_soundtransform, "avm2/soundchannel_soundtransform", 49), + (as3_soundchannel_stop, "avm2/soundchannel_stop", 4), } // TODO: These tests have some inaccuracies currently, so we use approx_eq to test that numeric values are close enough. diff --git a/tests/tests/swfs/avm2/soundchannel_stop/noise.mp3 b/tests/tests/swfs/avm2/soundchannel_stop/noise.mp3 new file mode 100644 index 000000000..862f41452 Binary files /dev/null and b/tests/tests/swfs/avm2/soundchannel_stop/noise.mp3 differ diff --git a/tests/tests/swfs/avm2/soundchannel_stop/output.txt b/tests/tests/swfs/avm2/soundchannel_stop/output.txt new file mode 100644 index 000000000..0aabfc10a --- /dev/null +++ b/tests/tests/swfs/avm2/soundchannel_stop/output.txt @@ -0,0 +1,8 @@ +///var silence = new Silence(); +///var silence_channel = silence.play(); +///silence_channel.stop() +undefined +///var noise = new Noise(); +///var noise_channel = noise.play(0, 1); +///noise_channel.stop(); +undefined diff --git a/tests/tests/swfs/avm2/soundchannel_stop/silence.mp3 b/tests/tests/swfs/avm2/soundchannel_stop/silence.mp3 new file mode 100644 index 000000000..689c71398 Binary files /dev/null and b/tests/tests/swfs/avm2/soundchannel_stop/silence.mp3 differ diff --git a/tests/tests/swfs/avm2/soundchannel_stop/test.fla b/tests/tests/swfs/avm2/soundchannel_stop/test.fla new file mode 100644 index 000000000..8c7f8bd68 Binary files /dev/null and b/tests/tests/swfs/avm2/soundchannel_stop/test.fla differ diff --git a/tests/tests/swfs/avm2/soundchannel_stop/test.swf b/tests/tests/swfs/avm2/soundchannel_stop/test.swf new file mode 100644 index 000000000..67effe853 Binary files /dev/null and b/tests/tests/swfs/avm2/soundchannel_stop/test.swf differ