Hls Metadata Id3 Tag Not Working

HLS Metadata ID3 tag not working

Your code works fine, the reason of this problem is caused by an issue from the server side.

You can use this tool mp3tag to edit the audio file - add meta data tags and upload it to server.

As examples, you can try these audios included metadata tags:

http://ice1.somafm.com/groovesalad-128-mp3

https://developer.jwplayer.com/jw-player/demos/basic/audio-metadata/assets/index.m3u8

To confirm, the above files should work fine with your code.

how to read id3 tags / other metadata from an HLS stream in swift / AVKIT

This is how I achieved it:

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!)")
}
}
}
}


Related Topics



Leave a reply



Submit