如何在iPhone上播放mp3 [英] how to play mp3 in iphone
问题描述
我正在为iPhone中的mp3播放器创建应用程序
我将.mp3文件复制到Resource文件夹中,并且该框架也可用
而且我的代码是runnig我没有收到任何错误,但是我没有通过耳机听到声音
代码-(void)viewDidLoad {
[super viewDidLoad];
NSString * path = [[NSBundle mainBundle] pathForResource:@"dtph" ofType:@"mp3"];
NSURL * file = [[[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer * p = [[[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
[文件发布];
self.player = p;
[p版本];
[player prepareToPlay];
[player setDelegate:self];
}
-(IBAction)玩{
//self.playbutton.enabled = NO;
//[玩家播放];
}
请帮助我
I am creating application for play mp3 in iphone
i copy .mp3 file in Resource folder and the framework is also available
and my code is runnig i am not getting any error but i am not hearing sound by headphone
code- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:@"dtph" ofType:@"mp3"];
NSURL *file=[[NSURL alloc]initFileURLWithPath:path];
AVAudioPlayer *p=[[AVAudioPlayer alloc]initWithContentsOfURL:file error:nil];
[file release];
self.player = p;
[p release];
[player prepareToPlay];
[player setDelegate:self];
}
-(IBAction) play{
//self.playbutton.enabled = NO;
//[player play];
}
plz help me
推荐答案
我不是Objective-C编程的输出,但是AVAudioPlayer
变量不应该是类成员吗?
现在,看来您正在创建AVAudioPlayer
的实例并释放它.
那是做什么的?
I''m not an export on Objective-C programming, but shouldn''t theAVAudioPlayer
variable be a class member ?
Now, it seems your are creating an instance of theAVAudioPlayer
and release it.
what does that do ?
self.player = p;
[p release];
还会释放self.player吗?
看看:
http://mobileorchard.com/easy-audio-playback-with-avaudioplayer/ [ ^ ]
最多
will it also release self.player ?
have a look at :
http://mobileorchard.com/easy-audio-playback-with-avaudioplayer/[^]
Max.
这篇关于如何在iPhone上播放mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!