|
@@ -34,6 +34,8 @@ static void * PlayerStatusObservationContext = &PlayerStatusObservationContext;
|
|
|
@property (nonatomic, copy) MKRAVPlayerURLRequsetBlcok block;
|
|
|
@property (nonatomic, assign) BOOL isSeeking;//是否快进或快退
|
|
|
@property (nonatomic, assign) NSTimeInterval seekTime;//快进或者快退的目标时间
|
|
|
+@property (nonatomic, strong) NSMutableArray *resourcePlayList;//MKRRadioResorce播放列表
|
|
|
+@property (nonatomic, assign) BOOL initByUrlPlayList;//是字符串播放列表
|
|
|
@end
|
|
|
|
|
|
@implementation MKRAVPlayer
|
|
@@ -69,6 +71,7 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
- (id)initWithPlayList:(NSArray<NSString *> *)playList{
|
|
|
self = [self init];
|
|
|
if (self) {
|
|
|
+ self.initByUrlPlayList = YES;
|
|
|
self.playList = playList;
|
|
|
}
|
|
|
return self;
|
|
@@ -85,6 +88,7 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
- (id)initWithContentURL:(NSURL *)aUrl{
|
|
|
self = [self init];
|
|
|
if (self) {
|
|
|
+ self.initByUrlPlayList = YES;
|
|
|
self.playUrl = aUrl;
|
|
|
self.playList = [NSArray arrayWithObject:aUrl];
|
|
|
}
|
|
@@ -97,21 +101,43 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
}
|
|
|
|
|
|
- (id)initWithObjectsPlayList:(NSArray<id<MKRRadioResorce>> *)playList{
|
|
|
- NSArray *urls = [playList valueForKey:@"songUrl"];
|
|
|
+ NSMutableArray *urls = [NSMutableArray arrayWithArray:[playList valueForKey:@"songUrl"]];
|
|
|
+ for (NSInteger i = 0; i<urls.count; i++) {
|
|
|
+ if ([urls[i] isEqual:[NSNull null]]) {
|
|
|
+ [urls replaceObjectAtIndex:i withObject:@""];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.resourcePlayList = [NSMutableArray arrayWithArray:playList];
|
|
|
return [self initWithPlayList:urls];
|
|
|
}
|
|
|
|
|
|
- (id)initWithObjectsPlayList:(NSArray<id<MKRRadioResorce>> *)playList playMode:(MKRAVPlayerPlayMode)playMode{
|
|
|
- NSArray *urls = [playList valueForKey:@"songUrl"];
|
|
|
+ NSMutableArray *urls = [NSMutableArray arrayWithArray:[playList valueForKey:@"songUrl"]];
|
|
|
+ for (NSInteger i = 0; i<urls.count; i++) {
|
|
|
+ if ([urls[i] isEqual:[NSNull null]]) {
|
|
|
+ [urls replaceObjectAtIndex:i withObject:@""];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.resourcePlayList = [NSMutableArray arrayWithArray:playList];
|
|
|
return [self initWithPlayList:urls playMode:playMode];
|
|
|
}
|
|
|
|
|
|
-- (void)updatePlayList:(NSArray<NSString *> *)playList{
|
|
|
- self.playList = playList;
|
|
|
- NSUInteger index = [playList indexOfObject:self.playUrl.absoluteString];
|
|
|
- if (index != NSNotFound) {
|
|
|
- self.currentIndex = index;
|
|
|
+- (void)updateResourcePlayList:(NSArray<id<MKRRadioResorce>> *)playList{
|
|
|
+ __block NSInteger index = 0;
|
|
|
+ [playList enumerateObjectsUsingBlock:^(id<MKRRadioResorce> obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+ if (obj.songID == self.currentResource.songID) {
|
|
|
+ index = idx;
|
|
|
+ *stop = YES;
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ NSMutableArray *urls = [NSMutableArray arrayWithArray:[playList valueForKey:@"songUrl"]];
|
|
|
+ for (NSInteger i = 0; i<urls.count; i++) {
|
|
|
+ if ([urls[i] isEqual:[NSNull null]]) {
|
|
|
+ [urls replaceObjectAtIndex:i withObject:@""];
|
|
|
+ }
|
|
|
}
|
|
|
+ self.currentIndex = index;
|
|
|
+ self.playList = urls;
|
|
|
}
|
|
|
|
|
|
#pragma mark - 播放相关
|
|
@@ -143,6 +169,7 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
self.currentIndex = index;
|
|
|
NSString *url = [self.playList objectAtIndex:index];
|
|
|
self.playUrl = MKRUrlWithString(url);
|
|
|
+ self.currentResource = self.resourcePlayList[index];
|
|
|
[self play];
|
|
|
}
|
|
|
}
|
|
@@ -228,6 +255,11 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)replayCurrentResource{
|
|
|
+ [self resetPlayer];
|
|
|
+ [self playAtIndex:self.currentIndex];
|
|
|
+}
|
|
|
+
|
|
|
- (void)resetPlayer{
|
|
|
self.totalTime = 0;
|
|
|
self.currentTime = 0;
|
|
@@ -394,6 +426,7 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
}
|
|
|
[self resetPlayer];
|
|
|
self.currentIndex = nextIndex;
|
|
|
+ self.currentResource = self.resourcePlayList[nextIndex];
|
|
|
self.currentStatus = nil;
|
|
|
NSString *url = [self.playList objectAtIndex:self.currentIndex];
|
|
|
self.playUrl = MKRUrlWithString(url);
|