|
@@ -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,12 +101,24 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
}
|
|
|
|
|
|
- (id)initWithObjectsPlayList:(NSArray<id<MKRRadioResorce>> *)playList{
|
|
|
- NSArray *urls = [playList valueForKey:@"songUrl"];
|
|
|
+ NSMutableArray *urls = [NSMutableArray arrayWithArray:[self.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:[self.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];
|
|
|
}
|
|
|
|
|
@@ -114,6 +130,16 @@ NSURL * MKRUrlWithString(NSString *string){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)updateResourcePlayList:(NSArray<id<MKRRadioResorce>> *)playList{
|
|
|
+ NSMutableArray *urls = [NSMutableArray arrayWithArray:[self.playList valueForKey:@"songUrl"]];
|
|
|
+ for (NSInteger i = 0; i<urls.count; i++) {
|
|
|
+ if ([urls[i] isEqual:[NSNull null]]) {
|
|
|
+ [urls replaceObjectAtIndex:i withObject:@""];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.playList = urls;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - 播放相关
|
|
|
|
|
|
- (void)play{
|
|
@@ -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];
|
|
|
}
|
|
|
}
|