小编And*_*Ley的帖子

AVAudioPlayer:MP3文件无法在设备上播放,但适用于模拟器(iOS 6)

我正在使用下面的代码在iOS 6上播放带有AVAudioPlayer的MP3文件.该文件似乎正在播放,但设备上没有声音输出.它在iOS模拟器中工作正常.

档案.h:

#import "UIKit/UIKit.h"
#import "AVFoundation/AVFoundation.h"

@interface ViewController : UIViewController <AVAudioPlayerDelegate>

@property (strong, nonatomic) AVAudioPlayer *player;

@end
Run Code Online (Sandbox Code Playgroud)

档案.m:

#import "ViewController.h"

@implementation ViewController

@synthesize player;

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"beep_7" ofType:@"mp3"];
    NSLog(@"Audio path: %@", soundFilePath);

    NSError *error;
    player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFilePath] error:&error];

    if (error) {
        NSLog(@"Error in audioPlayer: %@",[error localizedDescription]);
    } 
    else {
        [player setDelegate:self];
        [player setNumberOfLoops:3]; //just to make sure it is playing my file several times
        player.volume = 1.0f;

        if([player prepareToPlay]) …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c avaudioplayer ios

4
推荐指数
1
解决办法
2517
查看次数

标签 统计

avaudioplayer ×1

ios ×1

iphone ×1

objective-c ×1