HLS Metadata ID3 tag not working
Asked Answered
D

2

9

I have a list of audio URLs in a TableView, so every time I tapped on each cell on didSelectRowAt this method will be called

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // Prepare Audio URL
    let audioUrl = URL(string: (channelSelected.audioUrl?.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed))!)
    let playerItem = AVPlayerItem(url: audioUrl!)
    playerItem.addObserver(self, forKeyPath: "timedMetadata", options: .new, context: nil)
    player = AVPlayer(playerItem: playerItem)
    playerViewController = AVPlayerViewController()
    playerViewController.player = player
    present(playerViewController, animated: true, completion: {
        self.playerViewController.player?.play()
    })
}

And based on the tutorials, I implemented observe value listener

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    print("keypath = \(keyPath!)")
    let avPlayerItem: AVPlayerItem = object as! AVPlayerItem
    if let timedMetadata = avPlayerItem.timedMetadata {
        print("Timed metadata = \(timedMetadata)")
    } else {
        print("Timed metadata nil")
    }
}

The problem is that timedMetadata is always nil. Help would be appreciated.

Decor answered 5/4, 2018 at 2:41 Comment(15)
please give me audio URL, It may not be supported metadata Try this sound it works ice1.somafm.com/groovesalad-128-mp3Surat
@Surat can I pm you the audio URL?Decor
yes try this url ice1.somafm.com/groovesalad-128-mp3Surat
@Surat what is the complete url? It is not playing on my end. Is this correct? URL(string: "ice1.somafm.com/groovesalad-128-mp3.m3u8")!Decor
ok try this ur1 : developer.jwplayer.com/jw-player/demos/basic/audio-metadata/… url 2 : ice1.somafm.com/groovesalad-128-mp3 just add http:// first urlSurat
your url not be supported metadata this is server issue :)Surat
this URL(string: "http://ice1.somafm.com/groovesalad-128-mp3")Surat
Yes the jwplayer URL is now working. And I get the metadata, so this is a server issue.Decor
@Surat may I know what streaming server are you using? Are you familiar with Wowza?Decor
yes this is a server issue :)Surat
It has nothing to do with the Player or server but it is a problem in meta data tags read this document developer.jwplayer.com/jw-player/demos/basic/audio-metadata/…Surat
@Surat thanks for clarifying. I have little experience on this. Can you answer so I can acceptDecor
using this tool mp3tag.de/en you can edit audio file add meta data tags and upload to serverSurat
@Surat Thanks! Can you add that as an answer so I can accept thanks!Decor
i added my answer :)Surat
S
10

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.

Surat answered 7/4, 2018 at 13:2 Comment(0)
D
3

This is another alternative because I found out the server was not using "timed metadata". Here is how we implemented on our end, for those who haven't found an answer. The backend is using Wowza Server.

let playerItem = AVPlayerItem(url: audioUrl!)
let adID = AVMetadataItem.identifier(forKey: "X-TITLE", keySpace: .hlsDateRange)
let metadataCollector = AVPlayerItemMetadataCollector(identifiers: [adID!.rawValue], classifyingLabels: nil)
        metadataCollector.setDelegate(self, queue: DispatchQueue.main)
playerItem.add(metadataCollector)

and then declare an extension of AVPlayerItemMetadataCollectorPushDelegate

    func metadataCollector(_ metadataCollector: AVPlayerItemMetadataCollector, didCollect metadataGroups: [AVDateRangeMetadataGroup], indexesOfNewGroups: IndexSet, indexesOfModifiedGroups: IndexSet) {
             for metadataGroup in metadataGroups {
                     for metadata in metadataGroup.items {
             }
                     }
    }
Decor answered 13/4, 2018 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.