Bladeren bron

版本升级维护

yyqxiaoyin 5 jaren geleden
bovenliggende
commit
5cd9026a44

+ 12 - 0
MKRRadioManager/Classes/MKRRadioManager/MKRWIFIDeviceManager/MKRWIFIDeviceManager.h

@@ -19,6 +19,16 @@
 /** 搜索到新设备 */
 - (void)didSearchNewDevice:(NSDictionary *)newDecice;
 
+/// 收到设备广播的播放状态改变
+/// @param playState 改变后的播放状态
+/// @param deviceUUID 状态改变的设备的UUID
+- (void)didReceivePlayStateChange:(MKRResourcePlayState)playState;
+
+/// 收到设备广播的播放频道改变
+/// @param channel 频道号
+/// @param deviceUUID 频道号改变的设备的UUID
+- (void)didReceivePlayingChannelChange:(NSInteger)channel;
+
 @end
 
 @interface MKRWIFIDeviceManager : NSObject
@@ -27,6 +37,8 @@
 
 @property (nonatomic, strong)NSString *userID;
 
+@property (nonatomic, strong) id<MKRUPnPDevice> device;
+
 - (void)addDeviceManagerListener:(id<MKRWIFIDeviceManagerDelegate>)listener;
 
 - (void)removeDeviceManagerListener:(id<MKRWIFIDeviceManagerDelegate>)listener;

+ 74 - 22
MKRRadioManager/Classes/MKRRadioManager/MKRWIFIDeviceManager/MKRWIFIDeviceManager.m

@@ -11,6 +11,7 @@
 #import <pthread.h>
 #import <libAS-Control/ASControlTools.h>
 #import <libAS-Control/NSDictionary+MKRXml.h>
+#import <NSHashTable+MKRRadioManagerAdd.h>
 
 static inline void wd_main_queue(void (^block)(void)){
     if (pthread_main_np()) {
@@ -177,15 +178,33 @@ static inline void wd_playControl_queue(void (^block)(void)){
 #pragma mark - ASControlDelegate
 
 -(void)ReceivedPlayCallBack:(NSString *)nUDN{
-    NSLog(@"%s",__func__);
+    NSLog(@"收到播放回调%@",nUDN);
+    wd_main_queue(^{
+        if ([nUDN isEqualToString:self.device.deviceUUID]) {
+            self.currentResource.resourceStatus.playState = MKRResourcePlayStatePlaying;
+            [self.listeners makeObjectsPerformSelectorWithObjects:@selector(didReceivePlayStateChange:),MKRResourcePlayStatePlaying];
+        }
+    });
 }
 
 -(void)ReceivedPauseCallBack:(NSString *)nUDN{
-    NSLog(@"%s",__func__);
+    NSLog(@"收到暂停回调%@",nUDN);
+    wd_main_queue(^{
+        if ([nUDN isEqualToString:self.device.deviceUUID]) {
+            self.currentResource.resourceStatus.playState = MKRResourcePlayStatePause;
+            [self.listeners makeObjectsPerformSelectorWithObjects:@selector(didReceivePlayStateChange:),MKRResourcePlayStatePause];
+        }
+    });
 }
 
 -(void)ReceivedStopCallBack:(NSString *)nUDN{
-    NSLog(@"%s",__func__);
+    NSLog(@"收到停止回调%@",nUDN);
+    wd_main_queue(^{
+        if ([nUDN isEqualToString:self.device.deviceUUID]) {
+            self.currentResource.resourceStatus.playState = MKRResourcePlayStateStopped;
+            [self.listeners makeObjectsPerformSelectorWithObjects:@selector(didReceivePlayStateChange:),MKRResourcePlayStateStopped];
+        }
+    });
 }
 
 -(void)ReceivedSetVolumeCallBack:(NSString *)nUDN Volume:(NSInteger)Volume{
@@ -259,6 +278,12 @@ static inline void wd_playControl_queue(void (^block)(void)){
 
 -(void)ReceivedChangeChannelCallBack:(NSString *)nUDN Channel:(NSString *)channel{
     NSLog(@"%s",__func__);
+    NSLog(@"收到频道改变回调%@",nUDN);
+    wd_main_queue(^{
+        if ([nUDN isEqualToString:self.device.deviceUUID]) {
+            [self.listeners makeObjectsPerformSelectorWithObjects:@selector(didReceivePlayingChannelChange:),[channel integerValue]];
+        }
+    });
 }
 
 -(void)getLocalIp:(NSString *)Ip{
@@ -361,9 +386,10 @@ static inline void wd_playControl_queue(void (^block)(void)){
     NSString *timestamp = [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
     NSString *channelNumString = [NSString stringWithFormat:@"CHANNEL_UPDATE_%zd",song.songChannel];
     NSString *userID = self.userID;
+    NSString *songUrlString = [NSString stringWithFormat:@"AIRSMART//ID_%zd//",song.songID];
     libupnp_SetAVTransportURI(
     device.avTransportUrl,
-    song.songUrl?:@"",
+    songUrlString,
     song.songName?:@"",
     song.songArtist?:@"",
     song.songAlbum?:@"",
@@ -398,7 +424,7 @@ static inline void wd_playControl_queue(void (^block)(void)){
     timestamp,
     userID,
     playListUrl,
-    @"1"
+    @"0"
     );
 }
 
@@ -508,23 +534,45 @@ static inline void wd_playControl_queue(void (^block)(void)){
             return ;
         }
         @synchronized (self.currentResource) {
-            self.currentResource.songName = resultDic[@"TrackMetaData"][@"upnp:songName"];
-            self.currentResource.songArtist = resultDic[@"TrackMetaData"][@"upnp:songPlayer"];
-            self.currentResource.songAlbumCover = resultDic[@"TrackMetaData"][@"upnp:songThumb"];
-            self.currentResource.songID = [resultDic[@"TrackMetaData"][@"upnp:songInfoID"] integerValue];
-            id songFrom = resultDic[@"TrackMetaData"][@"upnp:songPlatform"];
-            if (![songFrom isKindOfClass:NSString.class]) {
-                songFrom = @"0";
+            if ([resultDic[@"TrackMetaData"][@"upnp:songName"] isKindOfClass:NSString.class]) {
+                self.currentResource.songName = resultDic[@"TrackMetaData"][@"upnp:songName"];
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songPlayer"] isKindOfClass:NSString.class]) {
+                self.currentResource.songArtist = resultDic[@"TrackMetaData"][@"upnp:songPlayer"];
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songThumb"] isKindOfClass:NSString.class]) {
+                self.currentResource.songAlbumCover = resultDic[@"TrackMetaData"][@"upnp:songThumb"];
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songInfoID"] isKindOfClass:NSString.class]) {
+                self.currentResource.songID = [resultDic[@"TrackMetaData"][@"upnp:songInfoID"] integerValue];
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songPlatform"] isKindOfClass:NSString.class]) {
+                self.currentResource.songFrom = [resultDic[@"TrackMetaData"][@"upnp:songPlatform"] integerValue];
+            }
+            if ([resultDic[@"TrackDuration"] isKindOfClass:NSString.class]) {
+                self.currentResource.resourceStatus.totalTime = [NSString secondsFromHHmmssFormatStrig:resultDic[@"TrackDuration"]];
+            }
+            if ([resultDic[@"RelTime"] isKindOfClass:NSString.class]) {
+                self.currentResource.resourceStatus.currentTime = [NSString secondsFromHHmmssFormatStrig:resultDic[@"RelTime"]];
             }
-            self.currentResource.songFrom = [songFrom integerValue];
-            self.currentResource.resourceStatus.totalTime = [NSString secondsFromHHmmssFormatStrig:resultDic[@"TrackDuration"]];
-            self.currentResource.resourceStatus.currentTime = [NSString secondsFromHHmmssFormatStrig:resultDic[@"RelTime"]];
-            self.currentResource.resourceStatus.playState = [self.currentResource.resourceStatus updatePlayState:resultDic[@"CurrentTransportState"]];
-            NSInteger sourceType = [MKRM3UListModel convertSorceTypeWithAudioType:[resultDic[@"TrackMetaData"][@"upnp:songType"] integerValue]];
-            self.currentResource.sourceType = sourceType;
-            id songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
-            if ([songAlbumID isKindOfClass:NSString.class]) {
-                self.currentResource.songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
+            if ([resultDic[@"CurrentTransportState"] isKindOfClass:NSString.class]) {
+                self.currentResource.resourceStatus.playState = [self.currentResource.resourceStatus updatePlayState:resultDic[@"CurrentTransportState"]];
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songType"] isKindOfClass:NSString.class]) {
+                NSInteger sourceType = [MKRM3UListModel convertSorceTypeWithAudioType:[resultDic[@"TrackMetaData"][@"upnp:songType"] integerValue]];
+                self.currentResource.sourceType = sourceType;
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songAlbumID"] isKindOfClass:NSString.class]) {
+                id songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
+                if ([songAlbumID isKindOfClass:NSString.class]) {
+                    self.currentResource.songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
+                }
+            }
+            if ([resultDic[@"TrackMetaData"][@"upnp:songAlbumID"] isKindOfClass:NSString.class]) {
+                id songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
+                if ([songAlbumID isKindOfClass:NSString.class]) {
+                    self.currentResource.songAlbumID = resultDic[@"TrackMetaData"][@"upnp:songAlbumID"];
+                }
             }
             NSString *channelString = resultDic[@"TrackMetaData"][@"upnp:songFlag"];
             NSInteger songChannel = 0;
@@ -537,12 +585,16 @@ static inline void wd_playControl_queue(void (^block)(void)){
             self.currentResource.songChannel = songChannel;
             NSString *songChannelUid = [NSString stringWithFormat:@"%@-%@-%zd",self.userID,device.deviceUUID,songChannel];
             self.currentResource.songChannelUid = songChannelUid;
-            self.currentResource.songFlag = [NSString stringWithFormat:@"%@_%@_%zd",songChannelUid,resultDic[@"TrackMetaData"][@"upnp:songInfoID"],[songFrom integerValue]];
+            self.currentResource.songFlag = [NSString stringWithFormat:@"%@_%zd_%zd",songChannelUid,self.currentResource.songID,self.currentResource.songFrom];
         }
     });
     return self.currentResource;
 }
 
+- (void)mkr_setObject:(id)obj forKey:(NSString *)key{
+    
+}
+
 - (id<MKRRadioResorce>)currentResource{
     if (!_currentResource) {
         _currentResource = [[MKRRadioResorce alloc] init];

+ 17 - 0
libs/libAS-Control.framework/Headers/ASControlTools.h

@@ -144,6 +144,23 @@ int libupnp_SetAVTransportURI(NSString *controlurl,
                               NSString *songFrom,//来源类别
                               NSString *songAlbumID);//专辑ID
 
+int libupnp_SetAVTransportURIV2(NSString *controlurl,
+                              NSString *encodedURL,
+                              NSString *title,//歌曲名
+                              NSString *artist,//艺人
+                              NSString *album,//专辑名
+                              NSString *albumArtUri,//专辑封面
+                              NSString *duration,//歌曲时长
+                              NSString *protocolInfo,//文件类型
+                              NSString *upnpclass,
+                              NSString *Timestamp,
+                              NSString *channelNum,
+                              NSString *songOrder,
+                              NSString *controlpoint,
+                              NSString *songID,
+                              NSString *songFrom,//来源类别
+                              NSString *songAlbumID);//专辑ID
+
 int libupnp_SetAVTransportURI_DLNA(NSString *controlurl,
                                    NSString *encodedURL,
                                    NSString *title,//歌曲名

BIN
libs/libAS-Control.framework/libAS-Control