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 有问题但文件仍然无法播放,我是初学者所以请放轻松,谢谢 :)

4

1 回答 1

0

尝试这个:

http://mobileorchard.com/easy-audio-playback-with-avaudioplayer/

于 2012-07-14T19:48:56.953 回答