Skip to content

Commit 4c8f882

Browse files
committed
avm2: Implement Sound.loadCompressedDataFromByteArray
1 parent d76306d commit 4c8f882

File tree

1 file changed

+19
-7
lines changed
  • core/src/avm2/globals/flash/media

1 file changed

+19
-7
lines changed

core/src/avm2/globals/flash/media/sound.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,26 @@ pub fn load<'gc>(
264264
/// `Sound.loadCompressedDataFromByteArray`
265265
pub fn load_compressed_data_from_byte_array<'gc>(
266266
activation: &mut Activation<'_, 'gc>,
267-
_this: Object<'gc>,
268-
_args: &[Value<'gc>],
267+
this: Object<'gc>,
268+
args: &[Value<'gc>],
269269
) -> Result<Value<'gc>, Error<'gc>> {
270-
avm2_stub_method!(
271-
activation,
272-
"flash.media.Sound",
273-
"loadCompressedDataFromByteArray"
274-
);
270+
let bytearray = args.get_object(activation, 0, "bytes")?;
271+
let bytes_length = args.get_u32(activation, 1)?;
272+
let bytearray = bytearray.as_bytearray().unwrap();
273+
274+
// FIXME - determine the actual errors thrown by Flash Player
275+
let bytes = bytearray.read_bytes(bytes_length as usize).map_err(|e| {
276+
Error::RustError(format!("Missing bytes from sound bytearray: {e:?}").into())
277+
})?;
278+
279+
let handle = activation.context.audio.register_mp3(bytes).map_err(|e| {
280+
Error::RustError(format!("Failed to register sound from bytearray: {e:?}").into())
281+
})?;
282+
283+
this.as_sound_object()
284+
.unwrap()
285+
.set_sound(&mut activation.context, handle)?;
286+
275287
Ok(Value::Undefined)
276288
}
277289

0 commit comments

Comments
 (0)