Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rewind mp3 streams when reading/writing #509

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sdk/src/asset_handlers/mp3_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub struct Mp3IO {

impl CAIReader for Mp3IO {
fn read_cai(&self, input_stream: &mut dyn CAIRead) -> Result<Vec<u8>> {
input_stream.rewind()?;

let mut manifest: Option<Vec<u8>> = None;

if let Ok(tag) = Tag::read_from(input_stream) {
Expand All @@ -145,6 +147,8 @@ impl CAIReader for Mp3IO {
}

fn read_xmp(&self, input_stream: &mut dyn CAIRead) -> Option<String> {
input_stream.rewind().ok()?;

if let Ok(tag) = Tag::read_from(input_stream) {
for frame in tag.frames() {
if let Content::Private(private) = frame.content() {
Expand Down Expand Up @@ -181,6 +185,8 @@ impl RemoteRefEmbed for Mp3IO {
) -> Result<()> {
match embed_ref {
RemoteRefEmbedType::Xmp(url) => {
source_stream.rewind()?;

let header = ID3V2Header::read_header(source_stream)?;
source_stream.rewind()?;

Expand Down Expand Up @@ -337,6 +343,8 @@ impl CAIWriter for Mp3IO {
output_stream: &mut dyn CAIReadWrite,
store_bytes: &[u8],
) -> Result<()> {
input_stream.rewind()?;

let header = ID3V2Header::read_header(input_stream)?;
input_stream.rewind()?;

Expand Down
Loading