Guest User

Untitled

a guest
Jul 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // Attempt to play the new sound file.
  2. NSError *error = nil;
  3. player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error: &error];
  4. if (nil != error) {
  5. ZZLogInfo(@"AVAudioPlayer failed to create: %@.", error);
  6. }
  7. self.player = player;
  8. [self adjustVolume];
  9.  
  10. [player setDelegate:self];
  11. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  12. if ([player prepareToPlay]) {
  13. [player play];
  14. } else {
  15. [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
  16. }
  17.  
  18. - (void)adjustVolume
  19. {
  20. MPMusicPlayerController* appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  21.  
  22. self.lastAbsoluteVolume = [appMusicPlayer volume];
  23.  
  24. if (self.lastAbsoluteVolume < MinVolume) {
  25. [appMusicPlayer setVolume:MaxVolume];
  26. }
  27. }
Add Comment
Please, Sign In to add comment