Guys where there may be an error, the folder with the music is in the @ "/ Sounds / song.mp3" directory. I tried everything. On the simulator and on the device, notes are working = (NSError does not generate errors.

NSError *error; NSString* path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"]; AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error]; // // [player setVolume:1.f]; [player prepareToPlay]; // [player play]; NSLog(@"%@", error.localizedDescription); 
  • Well post your answer then - Max Mikheyenko
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky

1 answer 1

[SOLVED] AVAudioPlayer needs to be created in the property, not locally.

  @interface ViewController () @property (strong, nonatomic) AVAudioPlayer* player; @end NSError *error; NSString* path = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error]; [self.player setVolume:1.f]; [self.player prepareToPlay]; [self.player play]; NSLog(@"%@", error.localizedDescription);