访问 iPod 音乐库并显示长度的声音列表
我正在尝试访问 iPod 音乐库,然后当我的应用程序处于后台时创建本地通知。我想在本地通知中播放选定的声音。我的问题是 Apple 只允许那些少于 30 秒的文件。长度。
那么有没有办法只获取那些长度小于 30 秒的声音列表呢?
如果我得到此列表,那么我需要将所选媒体文件复制到我的资源包中。 然后我可以将其发送到我的本地通知。直到并且除非有任何方法可以将媒体项目直接发送到本地通知。
感谢大家的帮助..
I am trying access iPod music library and after that creating a local notification when my application is in background. I want to play the selected sound in local notification. My problem is Apple allow only those files which are less then 30sec. in length.
So is there any way to get list of only those sound which are less then 30sec length?
If I get this list then I need to copy the selected media file in my resource bundle.
Then I can paas it to my local notification. until and unless if there is any way to paas a media item directly to local notification.
Thanks to all for helping..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您只需要“音乐”下的项目(而不是播客或铃声),类似这样的内容应该可以工作:
不幸的是
MPMediaPropertyPredicate
不允许我们按“持续时间小于 30 秒”进行过滤(比较类型为“EqualTo”和“Contains”),所以我们上面手动执行。然后您需要使用
AVAssetExportSession
导出所需的轨道。您可能需要将其转换为 本地和推送通知编程指南。我还建议使用固定文件名,以便更轻松地跟踪您创建的文件。最后,您无法写入应用程序包,因为这会使代码签名无效(显然您过去可以这样做;也许签名仅在安装时检查)。但是,您也许能够使用相对路径,例如
../Library/Application Support/MyApp/MySound.mp4
。请注意,这不能保证有效,并且可能会导致应用程序审核失败! 特别是,
../Library
开头。生成相对路径的算法超出了本答案的范围。 (绝对路径可能不起作用,因为它不能与-[NSString stringByAppendingPathComponent:]
一起使用。)UILocalNotification.soundName
会接受路径;该文档只是说它接受“应用程序主包中声音资源的文件名(包括扩展名)”。Assuming you want items under "music" only (not podcasts or ringtones), something like this should work:
Unfortunately
MPMediaPropertyPredicate
doesn't let us filter by "duration less than 30 seconds" (the comparison types are "EqualTo" and "Contains"), so we do it manually above.Then you need to export the desired track using
AVAssetExportSession
. You probably need to convert it to one of the supported formats in the Local and Push Notification Programming Guide. I also suggest using a fixed filename so it's easier to keep track of the files you've created.Finally, you can't write to your app bundle since this invalidates the code signature (apparently you used to be able to; perhaps the signature is only checked at install time). However, you might be able to use a relative path like
../Library/Application Support/MyApp/MySound.mp4
.Note that this is not guaranteed to work and might fail app review! In particular,
../Library
. An algorithm for generating relative paths is beyond the scope of this answer. (An absolute path probably won't work since it doesn't work with-[NSString stringByAppendingPathComponent:]
.)UILocalNotification.soundName
will accept a path; the documentation simply says it accepts a "filename (including extension) of a sound resource in the application’s main bundle".