IOS AVAudioPlayer 播放音频 没有声音问题解决

时间:2021-03-18 07:06:13

 

#import <UIKit/UIKit.h>

#import <AVFoundation/AVFoundation.h>

@interface MainViewController : UIViewController<AVAudioPlayerDelegate>

 

@property(nonatomic,strong)AVAudioPlayer *movePlayer ;

@end

 

 

 

#import "MainViewController.h"

 

@interface MainViewController ()

 

@end

 

@implementation MainViewController

@synthesize movePlayer;

- (void)viewDidLoad {

    // Do any additional setup after loading the view.

 

    

    [super viewDidLoad];

 

    

    NSString *filePath = [[NSBundle mainBundle]  pathForResource:@"1111" ofType:@"mp3"];

    NSURL *url = [NSURL fileURLWithPath:filePath];

    

 

   movePlayer =[[AVAudioPlayer  alloc] initWithContentsOfURL:url error:nil];

 

    movePlayer.delegate=self;

    

    [movePlayer prepareToPlay];

    [movePlayer play];

 

 

}