is it possible to read metadata using HTTP live streaming in the iPhone SDK

后端 未结 4 976
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 12:40

When playing a live stream using the HTTP Live Streaming method, is it possible read the current metadata (eg. Title and Artist)? This is for an iPhone radio app.

4条回答
  •  你的背包
    2021-01-31 12:48

    in swift 2.0 getting metadata info music streaming:

    PlayerItem.addObserver(self, forKeyPath: "timedMetadata", options: NSKeyValueObservingOptions.New, context: nil)
    

    add this method:

    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) {
    
        //Atualiza Nome Musica
        if keyPath == "timedMetadata" {
            if let meta = PlayerItem.timedMetadata {
                print("Novo Metadata \(meta)")
                for metadata in meta {
                    if let nomemusica = metadata.valueForKey("value") as? String{
                        LB_NomeMusica.text = nomemusica
                        if NSClassFromString("MPNowPlayingInfoCenter") != nil {
                            let image:UIImage = UIImage(named: "logo.gif")!
                            let albumArt = MPMediaItemArtwork(image: image)
                            var songInfo: [String:AnyObject] = [
                                MPMediaItemPropertyTitle: nomemusica,
                                MPMediaItemPropertyArtist: "Ao Vivo",
                                MPMediaItemPropertyArtwork: albumArt
                            ]
                            MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo
                        }
                    }
                }
            }
        }
    
    
    }
    

提交回复
热议问题