如何从swift / AVKIT的HLS流中读取id3标签/其他元数据

沃尔特·贝特

我正在尝试收集一些有关如何从iOS应用程序中的HLS流读取元数据的知识。以下HLS流具有一些我要阅读的ID3标签:HLS测试流

在Safari的Web检查器中,我能够在控制台中看到很多数据对象,每个对象都有元数据:

在此处输入图片说明

在Web检查器的“网络”选项卡中,我可以阅读播放列表文件:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-MEDIA-SEQUENCE:89147
#EXT-X-TARGETDURATION:20
#EXT-X-PROGRAM-DATE-TIME:2019-09-25T11:35:23.401Z
#EXTINF:19.970,
05-20190925T113523Z.aac
#EXTINF:19.970,
05-20190925T113543Z.aac
#EXTINF:19.970,
05-20190925T113603Z.aac
#EXTINF:19.970,
05-20190925T113623Z.aac
#EXTINF:19.970,
05-20190925T113643Z.aac
#EXTINF:19.970,
05-20190925T113703Z.aac

到目前为止,我已经实现了一个使用AVPlayer实例播放此流的类。它工作正常。

我从AVPlayer打印了各种属性AVPlayerItem到Xcode控制台。但是,我只能解释的属性是AVPlayerItem.currentTime给我EXT-X-PROGRAM-DATE-TIME播放列表文件中的值其他所有属性似乎与我在播放列表和id3标签中看到的信息无关。

有什么方法可以读取每个id3标签中包含的元数据?如何EXT-X-TARGETDURATION从播放列表中阅读

我阅读了有关的文章AVPlayerItemMetadataCollector,但是我不知道该怎么办,以及这是否有助于我阅读HLS流中的元数据。

沃尔特·贝特

这是我实现的方式:

import UIKit
import AVKit
import AVFoundation
import MediaPlayer

class ViewController: UIViewController{

    let player = AVPlayer()
    var playerItem: AVPlayerItem!
    let asset = AVAsset(url: URL(string: "https://db2.indexcom.com/bucket/ram/00/05/05.m3u8")!)

    override func viewDidLoad() {
        prepareToPlay()
        player.play()
    }

    func prepareToPlay() {
        playerItem = AVPlayerItem(asset: asset)
        playerItem.addObserver(self, forKeyPath: "timedMetadata", options: [], context: nil)
        player.replaceCurrentItem(with: playerItem)
        printTimeStamp()
    }

    func printTimeStamp() {
        print("▼⎺▼⎺▼⎺▼⎺▼⎺▼⎺▼⎺▼")
        print("PROGRAM-DATE-TIME: ")
        print(playerItem.currentDate() ?? "No timeStamp")
        print("▲_▲_▲_▲_▲_▲_▲_▲\n\n")
    }

    override func observeValue(forKeyPath: String?, of: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if forKeyPath != "timedMetadata" { return }

        printTimeStamp()

        let data: AVPlayerItem = of as! AVPlayerItem

        guard let timedMetadata = data.timedMetadata else { return }

        for item in timedMetadata {
            switch item.commonKey {

            case .commonKeyAlbumName?:
                print("AlbumName: \(item.value!)")
            case .commonKeyArtist?:
                print("Artist: \(item.value!)")
            case .commonKeyArtwork?:
                print("Artwork: \(item.value!)")
            case .commonKeyAuthor?:
                print("Author: \(item.value!)")
            case .commonKeyContributor?:
                print("Contributor: \(item.value!)")
            case .commonKeyCopyrights?:
                print("Copyrights: \(item.value!)")
            case .commonKeyCreationDate?:
                print("CreationDate: \(item.value!)")
            case .commonKeyCreator?:
                print("creator: \(item.value!)")
            case .commonKeyDescription?:
                print("Description: \(item.value!)")
            case .commonKeyFormat?:
                print("Format: \(item.value!)")
            case .commonKeyIdentifier?:
                print("Identifier: \(item.value!)")
            case .commonKeyLanguage?:
                print("Language: \(item.value!)")
            case .commonKeyMake?:
                print("Make: \(item.value!)")
            case .commonKeyModel?:
                print("Model: \(item.value!)")
            case .commonKeyPublisher?:
                print("Publisher: \(item.value!)")
            case .commonKeyRelation?:
                print("Relation: \(item.value!)")
            case .commonKeySoftware?:
                print("Software: \(item.value!)")
            case .commonKeySubject?:
                print("Subject: \(item.value!)")
            case .commonKeyTitle?:
                print("Title: \(item.value!)")
            case .commonKeyType?:
                print("Type: \(item.value!)")

            case .id3MetadataKeyAlbumTitle?:
                print("id3MetadataKeyAlbumTitle: \(item.value!)")

            default:
                print("other data: \(item.value!)")
            }
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从 ExoPlayer 中的 HLS 流中提取定时 ID3 元数据?

来自分类Dev

Swift的ID3标签

来自分类Dev

HTTP Live Streaming:如何在iOS8中使用Javascript监听嵌入为ID3标签的定时元数据?

来自分类Dev

如何比较mp3,文件中的flac音频数据,忽略标头数据(ID3标签)等?

来自分类Dev

是否可以使用ffmpeg在php中读取mp3 id3标签?如果是这样,那又如何?

来自分类Dev

如何在Swift中从PLIST读取数据?

来自分类Dev

如何在Swift中从PLIST读取数据?

来自分类Dev

如何使用诱变剂打印 ID3 标签

来自分类Dev

如何通过fileReference从本地上传的mp3中提取id3标签?(AS3)

来自分类Dev

Swift:如何从JSON数据读取JSON数据

来自分类Dev

如何在Swift中从其他ViewController重新加载TableView中的数据

来自分类Dev

如何在 Swift 中调用 Func 到其他 Func

来自分类Dev

如何从UIDatePicker获取数据-Swift

来自分类Dev

如何从Swift NSURLSession获取数据?

来自分类Dev

如何从UIDatePicker获取数据-Swift

来自分类Dev

如何从Swift NSURLSession获取数据?

来自分类Dev

如何使用UISegmentedControl更改Swift中的标签?

来自分类Dev

Swift 3:如何编写for(;;)循环

来自分类Dev

Swift 3:如何编写for(;;)循环

来自分类Dev

swift 3:如何添加 UISlider?

来自分类Dev

如何在Swift中读取类似JSON的数据

来自分类Dev

如何从xcode / swift中读取MySQL数据库

来自分类Dev

如何在swift2中从json读取数据

来自分类Dev

如何在没有 JS 标签显示在 HTML 中的情况下,使用 PHP 和 JS 从其他站点读取数据?

来自分类Dev

在Swift中,如何扩展typealias?

来自分类Dev

在Swift中,如何翻转UITableViewCell?

来自分类Dev

如何理解Swift中的curring?

来自分类Dev

如何理解Swift中的curring?

来自分类Dev

Swift中的枚举如何工作?

Related 相关文章

  1. 1

    如何从 ExoPlayer 中的 HLS 流中提取定时 ID3 元数据?

  2. 2

    Swift的ID3标签

  3. 3

    HTTP Live Streaming:如何在iOS8中使用Javascript监听嵌入为ID3标签的定时元数据?

  4. 4

    如何比较mp3,文件中的flac音频数据,忽略标头数据(ID3标签)等?

  5. 5

    是否可以使用ffmpeg在php中读取mp3 id3标签?如果是这样,那又如何?

  6. 6

    如何在Swift中从PLIST读取数据?

  7. 7

    如何在Swift中从PLIST读取数据?

  8. 8

    如何使用诱变剂打印 ID3 标签

  9. 9

    如何通过fileReference从本地上传的mp3中提取id3标签?(AS3)

  10. 10

    Swift:如何从JSON数据读取JSON数据

  11. 11

    如何在Swift中从其他ViewController重新加载TableView中的数据

  12. 12

    如何在 Swift 中调用 Func 到其他 Func

  13. 13

    如何从UIDatePicker获取数据-Swift

  14. 14

    如何从Swift NSURLSession获取数据?

  15. 15

    如何从UIDatePicker获取数据-Swift

  16. 16

    如何从Swift NSURLSession获取数据?

  17. 17

    如何使用UISegmentedControl更改Swift中的标签?

  18. 18

    Swift 3:如何编写for(;;)循环

  19. 19

    Swift 3:如何编写for(;;)循环

  20. 20

    swift 3:如何添加 UISlider?

  21. 21

    如何在Swift中读取类似JSON的数据

  22. 22

    如何从xcode / swift中读取MySQL数据库

  23. 23

    如何在swift2中从json读取数据

  24. 24

    如何在没有 JS 标签显示在 HTML 中的情况下,使用 PHP 和 JS 从其他站点读取数据?

  25. 25

    在Swift中,如何扩展typealias?

  26. 26

    在Swift中,如何翻转UITableViewCell?

  27. 27

    如何理解Swift中的curring?

  28. 28

    如何理解Swift中的curring?

  29. 29

    Swift中的枚举如何工作?

热门标签

归档