YOUPAILZAudioPlayer.m 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // YOUPAILZAudioPlayer.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/9/22.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZAudioPlayer.h"
  9. static YOUPAILZAudioPlayer *instance = nil;
  10. @implementation YOUPAILZAudioPlayer
  11. + (instancetype)sharedInstance {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. instance = [[YOUPAILZAudioPlayer alloc] init];
  15. });
  16. return instance;
  17. }
  18. - (instancetype)init {
  19. self = [super init];
  20. if (!self) {
  21. return nil;
  22. }
  23. [self youpaifinitPlayer];
  24. return self;
  25. }
  26. - (void)youpaifinitPlayer {
  27. [self.youpaipplayer prepareToPlay];
  28. }
  29. - (AVAudioPlayer *)youpaipplayer {
  30. if (!_youpaipplayer) {
  31. NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"SomethingJustLikeThis" withExtension:@"mp3"];
  32. AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
  33. audioPlayer.numberOfLoops = NSUIntegerMax;
  34. _youpaipplayer = audioPlayer;
  35. }
  36. return _youpaipplayer;
  37. }
  38. @end