iOS13.1 AVAudioPlayer目标-c EXC_BAD_ACCESS

时间:2019-09-27 12:34:24

标签: objective-c iphone avaudioplayer

iOS13.1 AVAudioPlayer目标-c错误:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)

AVAudioPlayer + Extension.h文件:

@interface AVAudioPlayer (Extension)

- (instancetype)initWithFilepath:(NSString*)filepath
                       delegate:(id<AVAudioPlayerDelegate>)delegate;

AVAudioPlayer + Extension.m文件:

#import "AVAudioPlayer+Extension.h"

@implementation AVAudioPlayer (Extension)

@implementation AVAudioPlayer (Extension)

- (instancetype)initWithFilepath:(NSString*)filepath
                        delegate:(id<AVAudioPlayerDelegate>)delegate {

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

    if (error != nil) {
        NSLog(@"AVAudioPlayer init failed %@", [error localizedDescription]);
        return nil;
    }


    player.currentTime = 0;
    player.delegate = delegate;

    return player;
}

0 个答案:

没有答案