遇到一个问题,新建一个工程,运行以下代码,可以正常运行,但没有声音。
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property AVPlayer *player;
@property Float64 duration;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)btn_player:(id)sender {
NSURL* url = [NSURL fileURLWithPath:@"/Users/ben_gao/Desktop/1.mp3"];
if(!_player){
NSLog(@"initialize...");
_player = [[AVPlayer alloc] initWithURL:url];
}
[_player play];
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
@end
解决方案:关闭工程的SandBox选项。