AudioPlayer iOS和m4a [英] AudioPlayer iOS and m4a

查看:297
本文介绍了AudioPlayer iOS和m4a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个使用AVAudioPlayer播放音乐的应用程序.它可以上传或下载歌曲,将它们写入Core Data,然后在选定时调出它们播放.我正在测试的所有15首歌曲都可以在iPhone Music Client和我自己的计算机上正常运行.

I've made an app that plays music using AVAudioPlayer. It either uploads or downloads songs, writes them to Core Data, then recalls them to play when selected. All of the fifteen songs that I've been testing with operate normally using both the iPhone Music Client and my own computer.

但是,其中三个没有在应用程序上播放.具体来说,我可以按任何顺序上传这15首歌曲,清除我的Model.sqlite,再次将它们下载到应用程序中,然后发现其中3首只是没有播放.但是,他们确实拥有正确的标题和艺术家.

However, three of them don't play back on the app. Specifically, I can upload these fifteen songs in any order, clear my Model.sqlite, download them again into the app, and find that three of them just don't play. They do, however, have the right title and artist.

对此,我注意到,区别在于非工作文件是.m4a.如何使用AVAudioPlayer播放这种格式的文件?

Looking into this, I noticed that the difference is that the non-working files are .m4a. How do I play files of that format with AVAudioPlayer?

编辑(什么是回叫?",您使用哪个URL初始化AVAudioPlayer?"):

EDIT ("Whats "recalling?", what URL do you initialise AVAudioPlayer with?"):

有一台服务器,用户可以通过该应用访问歌曲.选择要检索的子集S后,应用程序将下载S并将其使用NSManagedObjectContext写入CoreModel.每首歌曲都存储为具有唯一ID和与子集实体(在本例中为S)的关系的独立实体.

There is a server with songs that the user can access through the app. After choosing which subset S to retrieve, the app then downloads S and writes it to a CoreModel using NSManagedObjectContext. Each song is stored as a separate entity with a unique ID and a relationship to a subset entity (in this case, S).

当我使用AppDelegate调用"以使用上下文获取正确的歌曲时,也会返回数据.然后,我像这样初始化AVAudioPlayer:

When I "recall" using the AppDelegate to get the right song using the context, the data is returned as well. I then initialize the AVAudioPlayer like so:

[[AVAudioPlayer alloc] initWithData:(NSData *)[currentSong valueForKey:@"data"] error:nil];

...所以我写了那封信,然后意识到我实际上并没有检查出错误所在(对不起,我).我发现它是OSStatus error 1954115647,它以不受支持的文件类型返回.进一步研究一下,我发现了 iPhone:AVAudioPlayer不支持的文件类型.在那里提出了一种解决方案,要么从一开始就修剪不良数据,要么从URL的内容初始化.是否有可能在核心模型中找到将数据写入的位置以作为URL来提供?

... So I wrote that and then realized that I haven't actually checked out what the error is (silly me). I found that it's OSStatus error 1954115647, which returns as Unsupported File Type. Looking into this a bit more, I found this iPhone: AVAudioPlayer unsupported file type. A solution is presented there as either trimming off bad data in the beginning or initializing from the contents of a URL. Is it possible to find where the data is written to in core model to feed that as the URL?

(比较文件.它们不同吗?)

(Compare files. Are they different?)

是的,他们是.我正在从服务器中获取一个示例.m4a文件,该文件由应用程序上传,并将其与iTunes中的文件进行比较.我发现该文件在偏移229404(从2906191字节开始)之前被切断,该偏移以20680001 A0000E21开始.在iTunes版本中,0028D83B 6D646174位于这些字节之前.在此之前,是一个很大的零块,后面是一个很大的数据块,然后是iTunes编码信息.最顶部是更多编码信息,列出文件为M4A.

Yes, they are. I'm grabbing a sample .m4a file from my server, which was uploaded by the app, and comparing it to the one that's in iTunes. What I found is that the file is cut off before offset 229404 (out of 2906191 bytes), which starts 20680001 A0000E21. In the iTunes version, 0028D83B 6D646174 lies before those bytes. Before that is a big block of zeroes preceded by a big block of data preceded by iTunes encoding information. At the very top is more encoding information listing the file as being M4A.

推荐答案

这不是直接的解决方案,但您可能

This is not a direct solution, but you probably shouldn't be saving the blobs in Core Data directly. Write the files to a cached location and save the file paths in Core Data. This will both use the database more efficiently and give you a local file path to give to your AVAudioPlayer, which will bypass the problem.

这篇关于AudioPlayer iOS和m4a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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