试图通过iPhone模拟器播放声音 [英] Trying to play sound through iPhone Simulator

查看:110
本文介绍了试图通过iPhone模拟器播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从iPhone程序播放声音文件。



以下是代码:

  NSString * path = [[NSBundle mainBundle] pathForResource:@playofType:@caf]; 
NSFileHandle * bodyf = [NSFileHandle fileHandleForReadingAtPath:path];
NSData * body = [bodyf availableData];
NSLog(@length of play.caf%d,[body length]);
NSURL * url = [NSURL fileURLWithPath:path isDirectory:NO];
NSLog([url description]);
NSLog(@%d,AudioServicesCreateSystemSoundID((CFURLRef)url,& soundID));

第一个NSLog是检查我是否有访问该文件是显示文件的URL,第三个NSLog返回-1500发生了未指定的错误。



对于第二个NSLog,我得到以下输出: p>

file:// localhost / Users / alan / Library /应用程序敲响了一个应用程序。楬惯楴汤匠灵溃椯桐汤⁥枫畭慬潴⽲牥䄯䄯楬楬楴楴楴⽳䙂㕅㡂䌭䌭䐳㕅㡂䌭䌭䐳㠵䙃㠭㍃ⴷ䍁㈶灡灡㤴㈰䰯祡挮晡模拟器/用户/应用程序/ BFE5B819-C3D8-4DCF-8C37-AC6258AF4902 / LocateMe.app / play.caf



这是由于我误解了



任何想法出现了什么问题?



我有钥匙,允许我在设备上运行我的应用程序。



我发现我的.caf文件在应用程序在设备上运行时成功播放。



然后我尝试了各种选择。 >

60秒的.wav文件无法在模拟器和设备上正常工作。



一个.wav文件这是5秒长可以在模拟器上工作,但不是在设备上。



5秒长的.aiff文件在模拟器和设备上工作。 / p>

当你传递给AudioServicesCreateSystemSoundID


时,模拟器和设备正在检查文件

I'm trying to play a sound file from an iPhone program.

Here's the code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"play" ofType:@"caf"];
NSFileHandle *bodyf = [NSFileHandle fileHandleForReadingAtPath:path];
NSData *body = [bodyf availableData];
NSLog( @"length of play.caf %d",[body length] );
NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
NSLog( [url description] );
NSLog( @"%d", AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID) );

The first NSLog is to check that I have access to the file (I did), the second NSLog is to show the file URL, and the third NSLog returns -1500 "An unspecified error has occurred."

For the second NSLog, I get the following output:

file://localhost/Users/alan/Library/Application 敲慬楴敶瑓楲杮upport/iPhone蒠ꁻތĀ⾅獕牥⽳污湡䰯扩慲祲䄯灰楬慣楴湯匠灵潰瑲椯桐湯⁥楓畭慬潴⽲獕牥䄯灰楬慣楴湯⽳䙂㕅㡂㤱䌭䐳ⴸ䐴䙃㠭㍃ⴷ䍁㈶㠵䙁㤴㈰䰯捯瑡䵥⹥灡⽰汰祡挮晡imulator/User/Applications/BFE5B819-C3D8-4DCF-8C37-AC6258AF4902/LocateMe.app/play.caf

This is either due to my misunderstanding of the "description" method, or this contributes to the problem.

Any idea what is going wrong?

解决方案

An update on this.

I got my keys to allow me to run my app on the device.

I found that my .caf file successfully played when the app ran on the device.

I then tried various alternatives.

A .wav file that is 60 seconds long failed to work on the simulator and the device.

A .wav file that is 5 seconds long would work on the simulator, but not on the device.

A .aiff file that is 5 seconds long works on the simulator and the device.

It would be good to know definitively what the simulator and the device are checking about the file when it is passed to AudioServicesCreateSystemSoundID

这篇关于试图通过iPhone模拟器播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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