-
-
Save emilylaguna/72286e3326b6678750608aba28d6632c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fileURL = URL(fileURLWithPath: strongSelf.episodePath!) | |
do { | |
strongSelf.audioFile = try AVAudioFile(forReading: fileURL, commonFormat: AVAudioCommonFormat.pcmFormatFloat32, interleaved: false) | |
// AVAudioFile.length is an expensive operation (often in the seconds) so here we attempt to load a cached value instead | |
strongSelf.cachedFrameCount = DataManager.sharedManager.findFrameCount(episode: episode) | |
if strongSelf.cachedFrameCount == 0 { | |
// we haven't cached a frame count for this episode, do that now | |
strongSelf.cachedFrameCount = strongSelf.audioFile!.length | |
DataManager.sharedManager.saveFrameCount(episode: episode, frameCount: strongSelf.cachedFrameCount) | |
// If the audio file length is still 0 then way may not be able to read the file correctly | |
if strongSelf.cachedFrameCount == 0 { | |
throw PlaybackError.unableToOpenFile | |
} | |
} | |
} catch { | |
objc_sync_exit(strongSelf.playerLock) | |
PlaybackManager.shared.playbackDidFail(logMessage: error.localizedDescription, userMessage: nil) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment