如何在AVAudioPlayer Swift中播放RMTP音频网址

时间:2015-06-26 12:10:59

标签: swift core-audio avaudioplayer

我正在寻找一种在 AVAudioPlayer 中使用 RMTP 网址实现音频流的好方法。 有什么方法可以做到这一点?还是有什么建议吗?

由于

更新1:包含代码

所以这是代码:

let queue : dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
        dispatch_async(queue, { () -> Void in
            if let songData = NSData(contentsOfURL: url) {
                if let player = AVAudioPlayer(data: songData, error: nil) {
                    dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        self.audioPlayer = player

                        self.audioPlayer!.delegate = self

                        if let startTime = startingTime {
                            self.audioPlayer?.currentTime = startTime
                        }

                        self.audioPlayer!.prepareToPlay()
                        self.audioPlayer!.play()
                        self.delegate?.mmPlayerManagerDelegate_playerStartedPlaying()
                    })
                }
            }
            else {
                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    if appDelegate.bIsCurUserListener == false {
                        //=>    Call delegate
                        self.delegate?.mmPlayerManagerDelegate_prepareNextSongToPlay()
                    }
                })
            }
        })

网址在这里:

  • “rtmpLocation”:“rtmp://limelight-fmstream-42.musicnet.com/a4396/e1”,
  • “rtmpResource”:“mp4:/spl/114/602/883/spl_029.mp4?e = 1435348059& h = 8b4b2fd16683faa9bda9b4bab6d79705”,

0 个答案:

没有答案