dimitris-c / AudioStreaming

An AudioPlayer/Streaming library for iOS written in Swift using AVAudioEngine.
MIT License
266 stars 56 forks source link

We want to play m4a file but from two different button with different audio file having m4a format. #42

Closed appDeveloper7 closed 2 years ago

appDeveloper7 commented 2 years ago
let filePath1 =     "/var....myFile1.m4a"  // local audio file URL with m4a extension
let filePath2 =     "/var....myFile2.m4a" // local audio file URL with m4a extension

let player = AudioPlayer()  // Player initialisation

@IBAction func buttonOneClick(_ sender: Any) {
            player.play(url: URL(fileURLWithPath: filePath1))      
    }

 @IBAction func buttonTwoClick(_ sender: Any) {
            player.play(url: URL(fileURLWithPath: filePath2))      
    }

Scenario : When I played on buttonOneClick then player working fine and after completing first audio then click on buttonTwoClick then getting below error.

Xcode console throwing this error while playing second music : Error: ( "Couldn't parse the bytes from the stream. Status: It is not possible to produce output packets because the\nstreamed audio file's packet table or other defining information is not present or appears after the audio data." )

We want to play m4a file but from two different button with different audio file having m4a format. Could you please assist here?

Originally posted by @appDeveloper7 in https://github.com/dimitris-c/AudioStreaming/issues/41#issuecomment-1247583072

dimitris-c commented 2 years ago

As I said in the other issue, this is a limitation on the Apple's AudioFileStream which this library uses to parses the audio data. An m4a needs to be optimised and have its metadata info at the start of the file. This is the error you are receiving -> https://developer.apple.com/documentation/audiotoolbox/kaudiofilestreamerror_notoptimized

You need to convert the m4a data to an optimised format so that this library can read it.