IOS。流媒体互联网广播

时间:2014-11-20 10:43:42

标签: ios swift streaming audio-streaming

我需要播放不同格式的网络电台。我尝试播放无线电使用MPMoviePlayerController,但它在3-4秒后停止。

var urlAddress = "http://streaming.radionomy.com/Elium-ClubDance";
var url = NSURL( string:urlAddress);
var player = MPMoviePlayerController(contentURL: url)
player.movieSourceType = MPMovieSourceType.Streaming;
player.prepareToPlay();
player.play();

有人知道如何修复它吗?

1 个答案:

答案 0 :(得分:6)

从您的问题我创建一个新项目并尝试此代码:

import UIKit
import MediaPlayer

class ViewController: UIViewController {

var moviePlayer:MPMoviePlayerController!

override func viewDidLoad() {
    super.viewDidLoad()

    var url:NSURL = NSURL(string: "http://streaming.radionomy.com/Elium-ClubDance")!

    moviePlayer = MPMoviePlayerController(contentURL: url)

    moviePlayer.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)

    moviePlayer.view.sizeToFit()

    moviePlayer.movieSourceType = MPMovieSourceType.Streaming

    self.view.addSubview(moviePlayer.view)

    moviePlayer.fullscreen = true
    moviePlayer.prepareToPlay()
    moviePlayer.play()

    moviePlayer.controlStyle = MPMovieControlStyle.Embedded

    }
}

对我来说工作非常好。