声音无法在我的应用中播放

时间:2012-07-14 19:42:06

标签: iphone xcode audio

我已开始使用应用,我需要在启动应用后立即播放音频片段。这是我的视图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有问题但文件仍然无法播放的内容,我是初学者所以请放轻松我,谢谢:)

1 个答案:

答案 0 :(得分:0)