2

I want to programmatically navigate chapters of a mp4 video. The chapters work in QuickTime, so I assume the video format isn't the issue.

The code from this page should return an array of the chapters but only returns an empty one instead: https://developer.apple.com/documentation/avfoundation/media_playback/presenting_chapter_markers

let asset = AVAsset(url: <# Asset URL #>)
let chapterLocalesKey = "availableChapterLocales"
 
asset.loadValuesAsynchronously(forKeys: [chapterLocalesKey]) {
    var error: NSError?
    let status = asset.statusOfValue(forKey: chapterLocalesKey, error: &error)
    if status == .loaded {
        let languages = Locale.preferredLanguages
        let chapterMetadata = asset.chapterMetadataGroups(bestMatchingPreferredLanguages: languages)
        // Process chapter metadata.
    }
    else {
        // Handle other status cases.
    }
}

Has anyone an idea how to do it?

1058u4
  • 172
  • 1
  • 10

0 Answers0