AVAudioPlayer return wrong duration when MP3 File's magic number is 49443302

when audio file's magic number is 49443302 not 49443303, AVAudioPlayer's duration property return wrong value, actually it cause by engiTunSMPB but I want to know why it happen only in ID3 version 2 (49443302) example: only difference in two mp3 file is the magic number

and check the duration returns this result

source code under here

//
//  ContentView.swift
//  testAudioPlayer
//
//  Created by 김수환 on 6/7/24.
//

import SwiftUI
import AVFoundation

struct ContentView: View {
    @State var duration: Double = 0
    
    var body: some View {
        VStack {
            Button {
                guard let audioURL = Bundle.main.url(
                    forResource: "example",
                    withExtension: "mp3"
                ) else {
                    return
                }
                guard let audioplayer = try? AVAudioPlayer(contentsOf: audioURL) else {
                    return
                }
                duration = audioplayer.duration
                
            } label: {
                Text("press to check example1's duration")
            }
            .padding(.bottom, 30)
            
            Button {
                guard let audioURL = Bundle.main.url(
                    forResource: "example2",
                    withExtension: "mp3"
                ) else {
                    return
                }
                guard let audioplayer = try? AVAudioPlayer(contentsOf: audioURL) else {
                    return
                }
                duration = audioplayer.duration
                
            } label: {
                Text("press to check example2's duration")
            }
            .padding(.bottom, 30)
            
            Text("duration: \(duration)")
        }
        .padding()
    }
}
Answered by Engineer in 791159022

Please use Feedback Assistant to submit a bug report, and please post here the ID generated by Feedback Assistant.

Please use Feedback Assistant to submit a bug report, and please post here the ID generated by Feedback Assistant.

AVAudioPlayer return wrong duration when MP3 File's magic number is 49443302
 
 
Q