相关疑难解决方法(0)

如何在ios swift中播放来自URL的mp3音频

我正在获取mp3 url作为api调用的响应.我想播放那个音频,那我怎么能这样做呢?(ios swift)

这是我的回答

 {
    content = "En este primer programa se tratar\U00e1n asuntos tan importante como este y aquel sin descuidar un poco de todo lo dem\U00e1s";
    file = "http://radio.spainmedia.es/wp-content/uploads/2015/12/ogilvy.mp3";
    image = "http://radio.spainmedia.es/wp-content/uploads/2015/12/tapas.jpg";
    number = 0001;
    subtitle = Titulareando;
    title = "Tapa 1";
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码::

 @IBAction func btnplayaudio(sender: AnyObject) {
    let urlstring = "http://radio.spainmedia.es/wp-content/uploads/2015/12/tailtoddle_lo4.mp3"
    let url = NSURL(string: urlstring)
    print("the url = \(url!)")

    play(url!)

}

func play(url:NSURL) {
    print("playing \(url)")

    do {
        self.player = try AVAudioPlayer(contentsOfURL: url)
        player.prepareToPlay()
        player.volume …
Run Code Online (Sandbox Code Playgroud)

avaudioplayer ios swift ios9 swift2

19
推荐指数
7
解决办法
5万
查看次数

用AVAudioplayer流式传输

为了加载声音文件,我在我的应用程序中有以下代码:

- (id) init:(NSString*)a_filename ext:(NSString*)a_ext 
{
    ...

    NSString *t_soundFilePath = [CFileLoader getPathForResource:filename WithExtension:ext];
    NSURL *t_fileURL = [[[NSURL alloc] initFileURLWithPath: t_soundFilePath] autorelease];

    player = [[AVAudioPlayer alloc] initWithContentsOfURL: t_fileURL error: nil];
    [player prepareToPlay];
    ...

    }
Run Code Online (Sandbox Code Playgroud)

我加载的所有声音都在我的包中,所以我想知道方法"initwithcontentsofurl"是否流式传输声音文件或是否所有文件都被缓存.

我的应用程序中有很多精灵,所以我想减少用于声音的内存空间.

谢谢你的帮助

iphone streaming avaudioplayer

7
推荐指数
3
解决办法
1万
查看次数

标签 统计

avaudioplayer ×2

ios ×1

ios9 ×1

iphone ×1

streaming ×1

swift ×1

swift2 ×1