AVAUdioPlayer - 更改当前URL [英] AVAUdioPlayer - changing current URL

查看:101
本文介绍了AVAUdioPlayer - 更改当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的音频播放器应用程序中,如果我点击快进按钮 - 播放器必须找到播放列表中的下一首歌并播放它。我所做的是从下一首歌中获取URL,并尝试将其放在后台(后台是AVAudioPlayer的实例*)url字段,但该属性是只读的。所以我正在做的事情 - 我正在调用initWithContentsOfURL方法(再次)设置这样的URL:

In my audio player app, if I hit the fast forward button - the player must find the next song in the playlist and play it. What I do is I get the URL from the next song, and try to put it in the background (background is an instance of AVAudioPlayer*) url field, but that property is read only. So what I'm actually doing - I'm calling the initWithContentsOfURL method (again) to set the URL like this :

[self.background initWithContentsOfURL:
[[_playlist.collection objectAtIndex:currentIndex] songURL] error:nil];

这是合法的吗?我的意思是,编译器告诉我表达式结果是未使用的,但它实际上是有效的。
还有另一种方法吗?谢谢; - )

Is this legit? I mean, the compiler tells me that the expression result is unused, but it actually works. Is there another way of doing it? Thanks ;-)

推荐答案

检查过4个Apple样本,他们正在使用AVAudioPlayer播放一首歌曲。但是,你的结果看起来非常有趣和令人印象请告诉我们,如果您在重新初始化具有相同地址的对象之前停止播放,您是否正在开始新的音频会话?

Have checked 4 Apple samples, they are using AVAudioPlayer to play one song only. However, your result looks very interesting and impressive! Please let us know, are you stopping the playback before reinitializing object with the same address, are you starting the new audio session ?

至于我,我不会放回放和应用程序的稳定性冒险做了文档中没有提到的事情,但是,为了好的一面将使用AVAudioPlayer类,因为它似乎是最正确的,这给了我们:

As for me, I'd not put the playback and app stability in a risk doing something not mentioned in the documentation but , but to be on the bright side would use the AVAudioPlayer class as it seems the most right, which gives us:


  • 使用错误变量来跟踪可能的错误

  • 停止播放AVAudioPlayer实例,初始化AVAudioPlayer的新实例并将其设置为属性让旧的人自动解除分配。

你可能知道自己,

self.background = [self.background initWithContentsOfURL::

会删除警告。

这篇关于AVAUdioPlayer - 更改当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆