Closed lyarenei closed 4 months ago
I think this is the same issue discussed in #206 and I think it boils down to treating -openReturningError:
synchronously when it is inherently asynchronous in this case due to network requests.
This problem occurs because there are attempts to read data from the input source (via sf_open_virtual
in the case of WAVE, but it will differ by format) before the NSURLSessionDataTask
has made any calls to the delegate returning data from the request. When this happens the input source returns a zero length which is typically reported as an unsupported format.
I feel like this is a design flaw in the way that HTTP input sources are handled. Years ago HTTP input was implemented using CFReadStream
(see https://github.com/sbooth/SFBAudioEngine/blob/legacy/Input/HTTPInputSource.cpp if you're curious) which seemed to work at the time with the library's architecture. In the transition to Objective-C and Swift CFReadStream
was replaced with the current design.
I don't have a great fix off the top of my head, but one possibility is exposing SFBHTTPInputSource
as a public class and requiring users to ensure the network has returned data before trying to create a decoder from the input source. It's also possible that the library could handle that internally although I'm not sure what that would entail.
In a perfect world perhaps all reads would be asynchronous (taking a completion handler in Objective-C and using async
in Swift) but that would be significant change to the way things work.
Bringing in @NattyNarwhal for any suggestions.
I moved my application to AVFoundation, which from what I observe (could be inaccurate!) seems block only to load just enough of the file (metadata, maybe initial audio frames), then continues to load the rest in asynchronously behind the scenes; file progress is observable. You can also set an option to block a bit longer to load more data for more accurate seeks if the container can't be accurate about it.
In the SFBHTTPInputSource case, it seemed all the libraries it delegates to would fail because nothing was loaded of the file yet.
For now I've removed SFBHTTPInputSource
.
Hi, I'm currently evaluating SFBAudioEngine for my future iOS/macOS app using the
SimplePlayer
demo app. But when I try to play this mp3 sample remotely, it refuses to play, saying it's not a recognized format.The logs are not saying much, just TagLib reports that the file could not be opened and the download gets cancelled. It also looks like that 2 sessions for the download are spawned for some reason?
If I try a wav sample from the same site,
SimplePlayer
reports it as unsupported:I've tried multiple samples from multiple servers, but the errors are same. Local playback of these two samples mentioned above works without any issues. The only format I was able to stream successfully was FLAC.
I also think this might be related, or maybe it's even discussing the same issue: https://github.com/sbooth/SFBAudioEngine/discussions/206, but that looks like it ended up unresolved.
Unfortunately I don't know anything about objc, othwerwise I'd try to debug this further. Can you please take a look into it? Let me know if you need more details. Thanks.