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
How to Hide API Keys in Github for iOS (Swift) Projects
How to Get the Nondecoded Attributes from a Decoder Container in Swift 4
3D Touch Quick Actions Not Working at All
Include Pods in Main Target and Not in Watchkit Extension
Why am I Getting Com.Facebook.Sdk.Login Error 308
How to Handle Oauth-Style Log Ins with Imessage Apps in iOS 10, Xcode 8
Differrence Between Closure and Function as Argument in Swift
Restkit, Coredata and Swift - I Can't Seem to Fetch Results Back Out
Saving Contact Address to Unified Contact Results in (Cnerrordomain Error 500)
Swift Core Data Sync with Web Server
Core Data Transient Values with Swift
How to Programmatically Check and Open an Existing App in iOS 8
iOS Swift Detecting Image Rotation
Swiftui Multiple Navigationlinks in Form/Sheet - Entry Stays Highlighted
Swift: Protocol VS. Struct VS. Class
Add Progress to File Uploading Using Alamofire
How to Use Gadbannerviewdelegate to Perform Action on Adviewdidreceivead