LMMediaPlayer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // LMMediaPlayer.h
  3. // iPodMusicSample
  4. //
  5. // Created by Akira Matsuda on 2014/01/10.
  6. // Copyright (c) 2014年 Akira Matsuda. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. #import <MediaPlayer/MediaPlayer.h>
  11. #import <AVFoundation/AVFoundation.h>
  12. #import "LMMediaItem.h"
  13. @class LMMediaPlayer;
  14. typedef NS_ENUM(NSUInteger, LMMediaPlaybackState) {
  15. LMMediaPlaybackStateStopped,
  16. LMMediaPlaybackStatePlaying,
  17. LMMediaPlaybackStatePaused
  18. };
  19. typedef NS_ENUM(NSUInteger, LMMediaRepeatMode) {
  20. LMMediaRepeatModeDefault,
  21. LMMediaRepeatModeOne,
  22. LMMediaRepeatModeAll,
  23. LMMediaRepeatModeNone = LMMediaRepeatModeDefault
  24. };
  25. extern NSString *const LMMediaPlayerPauseNotification;
  26. extern NSString *const LMMediaPlayerStopNotification;
  27. @protocol LMMediaPlayerDelegate <NSObject>
  28. @required
  29. - (BOOL)mediaPlayerWillStartPlaying:(LMMediaPlayer *)player media:(LMMediaItem *)media;
  30. @optional
  31. - (void)mediaPlayerWillChangeState:(LMMediaPlaybackState)state;
  32. - (void)mediaPlayerDidStartPlaying:(LMMediaPlayer *)player media:(LMMediaItem *)media;
  33. - (void)mediaPlayerDidFinishPlaying:(LMMediaPlayer *)player media:(LMMediaItem *)media;
  34. - (void)mediaPlayerDidStop:(LMMediaPlayer *)player media:(LMMediaItem *)media;
  35. - (void)mediaPlayerDidChangeCurrentTime:(LMMediaPlayer *)player;
  36. - (void)mediaPlayerDidChangeRepeatMode:(LMMediaRepeatMode)mode player:(LMMediaPlayer *)player;
  37. - (void)mediaPlayerDidChangeShuffleMode:(BOOL)enabled player:(LMMediaPlayer *)player;
  38. @end
  39. @interface LMMediaPlayer : NSObject
  40. @property (nonatomic, assign) id<LMMediaPlayerDelegate> delegate;
  41. @property (nonatomic, readonly) LMMediaItem *nowPlayingItem;
  42. @property (nonatomic, readonly) LMMediaPlaybackState playbackState;
  43. @property (nonatomic, assign) LMMediaRepeatMode repeatMode;
  44. @property (nonatomic, readonly) BOOL shuffleMode;
  45. @property (nonatomic, readonly) NSInteger index;
  46. + (instancetype)sharedPlayer;
  47. - (AVPlayer *)corePlayer;
  48. - (void)pauseOtherPlayer;
  49. - (void)stopOtherPlayer;
  50. - (void)addMedia:(LMMediaItem *)media;
  51. - (void)removeMediaAtIndex:(NSUInteger)index;
  52. - (void)replaceMediaAtIndex:(LMMediaItem *)media index:(NSInteger)index;
  53. - (void)removeAllMediaInQueue;
  54. - (void)setQueue:(NSArray *)queue;
  55. - (void)playMedia:(LMMediaItem *)media;
  56. - (void)play;
  57. - (void)playAtIndex:(NSInteger)index;
  58. - (void)stop;
  59. - (void)pause;
  60. - (void)playNextMedia;
  61. - (void)playPreviousMedia;
  62. - (NSArray *)queue;
  63. - (NSUInteger)numberOfQueue;
  64. - (NSTimeInterval)currentPlaybackTime;
  65. - (NSTimeInterval)currentPlaybackDuration;
  66. - (void)seekTo:(NSTimeInterval)time;
  67. - (void)setShuffleEnabled:(BOOL)enabled;
  68. - (UIImage *)thumbnailAtTime:(CGFloat)time;
  69. - (UIImage *)representativeThumbnail;
  70. - (NSError *)setAudioSessionCategory:(NSString *)category;
  71. @end