2012-07-14 95 views
0

我已經開始使用應用程序,並且只要啓動應用程序,就需要播放音頻片段。這是我的看法Controller.m或者文件:聲音不會在我的應用程序中播放

// 
// ViewController.m 
// audio test 
// 
// Created by Kevin Patrick on 14/07/2012. 
// Copyright (c) 2012 Team Tops. All rights reserved. 
// 

#import "ViewController.h" 
#import <AVFoundation/AVFoundation.h> 

@interface ViewController() 

@end 

@implementation ViewController 

-(void)awakeFromNib { 

NSString *path = [[NSBundle mainBundle] 
        pathForResource:@"CPOP MUSIC"ofType:@"mp3"]; 
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] 
          initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
[theAudio play]; 
} 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

@end 

但是,當我模擬應用程序不播放任何聲音,它是空白,什麼都不做。我已經得到了支持文件夾中的音頻文件,我已經看到有關最新的Xcode有問題的東西,但該文件仍然不會播放,我是一個初學者,所以請容易對我,謝謝:)

+0

ARC結構,需要把AVAudioPlayer上的屬性,或將被從內存中釋放則沒有發揮 – GTSouza 2012-07-14 19:44:58

+0

對不起,我說我是個初學者,所以我會怎麼做你剛纔說過?謝謝 – user1483652 2012-07-14 19:45:50

回答

0
+0

你好,感謝您的快速回復,但我添加了上面的聲明,仍然音頻不播放,這是我的模擬器的問題? – user1483652 2012-07-14 20:02:22

+0

也許,請查看http://mobileorchard.com/easy-audio-playback-with-avaudioplayer/ – GTSouza 2012-07-14 20:05:27

+0

哦我的!!!!非常感謝你,我已經花了很多時間試圖獲得這樣一個簡單的事情,非常感謝你 – user1483652 2012-07-14 20:19:41

相關問題