|
@@ -19,6 +19,11 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static inline void wd_playControl_queue(void (^block)(void)){
|
|
|
+ dispatch_queue_t queue = dispatch_queue_create("com.maoking.playControlQueue", DISPATCH_QUEUE_SERIAL);
|
|
|
+ dispatch_async(queue, block);
|
|
|
+}
|
|
|
+
|
|
|
@interface MKRWIFIDeviceManager () <ASControlDelegate> {
|
|
|
int _upnpErrorCode;
|
|
|
NSMutableArray *_baseUrlArray;
|
|
@@ -27,6 +32,8 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
|
|
|
@property (nonatomic, strong) NSHashTable *listeners;
|
|
|
|
|
|
+@property (nonatomic, strong) id <MKRRadioResorce> currentResource;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation MKRWIFIDeviceManager
|
|
@@ -289,38 +296,40 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
}
|
|
|
|
|
|
- (void)setM3UList:(MKRM3UListModel *)m3uListModel {
|
|
|
- libupnp_SetNewM3UList(
|
|
|
- m3uListModel.secondsList,
|
|
|
- m3uListModel.artistList,
|
|
|
- m3uListModel.titleList,
|
|
|
- m3uListModel.urlList,
|
|
|
- m3uListModel.cueList,
|
|
|
- m3uListModel.startTimeList,
|
|
|
- m3uListModel.endTimeList,
|
|
|
- m3uListModel.vipCanPlay,
|
|
|
- m3uListModel.albumList,
|
|
|
- m3uListModel.albumArtUriList,
|
|
|
- m3uListModel.durationList,
|
|
|
- m3uListModel.protocolInfoList,
|
|
|
- m3uListModel.upnpclassList,
|
|
|
- m3uListModel.channelNumList,
|
|
|
- m3uListModel.songOrderList,
|
|
|
- m3uListModel.userID,
|
|
|
- m3uListModel.songIDList,
|
|
|
- m3uListModel.songFromList,
|
|
|
- m3uListModel.songAlbumIDList,
|
|
|
- m3uListModel.channelNO,
|
|
|
- m3uListModel.playModeString,
|
|
|
- m3uListModel.timeString,
|
|
|
- m3uListModel.channelPure,
|
|
|
- m3uListModel.channelAlbumID,
|
|
|
- m3uListModel.channelInfoString,
|
|
|
- m3uListModel.userID,
|
|
|
- m3uListModel.startIndex,
|
|
|
- m3uListModel.endIndex,
|
|
|
- m3uListModel.m3uSize,
|
|
|
- @""
|
|
|
- );
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_SetNewM3UList(
|
|
|
+ m3uListModel.secondsList,
|
|
|
+ m3uListModel.artistList,
|
|
|
+ m3uListModel.titleList,
|
|
|
+ m3uListModel.urlList,
|
|
|
+ m3uListModel.cueList,
|
|
|
+ m3uListModel.startTimeList,
|
|
|
+ m3uListModel.endTimeList,
|
|
|
+ m3uListModel.vipCanPlay,
|
|
|
+ m3uListModel.albumList,
|
|
|
+ m3uListModel.albumArtUriList,
|
|
|
+ m3uListModel.durationList,
|
|
|
+ m3uListModel.protocolInfoList,
|
|
|
+ m3uListModel.upnpclassList,
|
|
|
+ m3uListModel.channelNumList,
|
|
|
+ m3uListModel.songOrderList,
|
|
|
+ m3uListModel.userID,
|
|
|
+ m3uListModel.songIDList,
|
|
|
+ m3uListModel.songFromList,
|
|
|
+ m3uListModel.songAlbumIDList,
|
|
|
+ m3uListModel.channelNO,
|
|
|
+ m3uListModel.playModeString,
|
|
|
+ m3uListModel.timeString,
|
|
|
+ m3uListModel.channelPure,
|
|
|
+ m3uListModel.channelAlbumID,
|
|
|
+ m3uListModel.channelInfoString,
|
|
|
+ m3uListModel.userID,
|
|
|
+ m3uListModel.startIndex,
|
|
|
+ m3uListModel.endIndex,
|
|
|
+ m3uListModel.m3uSize,
|
|
|
+ @""
|
|
|
+ );
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)setAVTransportURIWithSong:(id <MKRRadioResorce>)song
|
|
@@ -328,24 +337,27 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
userID:(NSString *)userID {
|
|
|
NSString *timestamp = [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
|
|
|
NSString *channelNumString = [NSString stringWithFormat:@"CHANNEL_UPDATE_%zd",song.songChannel];
|
|
|
- libupnp_SetAVTransportURI(
|
|
|
- device.avTransportUrl,
|
|
|
- song.songUrl,
|
|
|
- song.songName,
|
|
|
- song.songArtist,
|
|
|
- song.songAlbum,
|
|
|
- song.songAlbumCover,
|
|
|
- @"0",
|
|
|
- @"null",
|
|
|
- @"null",
|
|
|
- timestamp,
|
|
|
- channelNumString,
|
|
|
- @"0",
|
|
|
- userID,
|
|
|
- @(song.songID).stringValue,
|
|
|
- @(song.songFrom).stringValue,
|
|
|
- song.songAlbumID?:@""
|
|
|
- );
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_SetAVTransportURI(
|
|
|
+ device.avTransportUrl,
|
|
|
+ song.songUrl,
|
|
|
+ song.songName,
|
|
|
+ song.songArtist,
|
|
|
+ song.songAlbum,
|
|
|
+ song.songAlbumCover,
|
|
|
+ @"0",
|
|
|
+ @"null",
|
|
|
+ @"null",
|
|
|
+ timestamp,
|
|
|
+ channelNumString,
|
|
|
+ @"0",
|
|
|
+ userID,
|
|
|
+ @(song.songID).stringValue,
|
|
|
+ @(song.songFrom).stringValue,
|
|
|
+ song.songAlbumID?:@""
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)playWithDevice:(id <MKRUPnPDevice>)device {
|
|
@@ -359,14 +371,17 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
NSString *playFlag = [NSString stringWithFormat:@"%zd-%zd",channelNO,index];
|
|
|
NSString *playListUrl = [NSString stringWithFormat:@"%@/web/playlist",[ASControlTools sharedInstanceUPNP].myIp];
|
|
|
NSString *timestamp = [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
|
|
|
- libupnp_PlayNumFlag(
|
|
|
- device.avTransportUrl,
|
|
|
- playFlag,
|
|
|
- timestamp,
|
|
|
- userID,
|
|
|
- playListUrl,
|
|
|
- @"1"
|
|
|
- );
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_PlayNumFlag(
|
|
|
+ device.avTransportUrl,
|
|
|
+ playFlag,
|
|
|
+ timestamp,
|
|
|
+ userID,
|
|
|
+ playListUrl,
|
|
|
+ @"1"
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)playSongWithChannelNO:(NSInteger)channelNO
|
|
@@ -376,76 +391,108 @@ static inline void wd_main_queue(void (^block)(void)){
|
|
|
}
|
|
|
|
|
|
- (void)pauseWithDevice:(id <MKRUPnPDevice>)device {
|
|
|
- libupnp_Pause(device.avTransportUrl);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_Pause(device.avTransportUrl);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)nextWithDevice:(id <MKRUPnPDevice>)device{
|
|
|
- libupnp_Previous(device.avTransportUrl);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_Previous(device.avTransportUrl);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)previousWithDevice:(id <MKRUPnPDevice>)device{
|
|
|
- libupnp_Previous(device.avTransportUrl);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_Previous(device.avTransportUrl);
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)stopWithDevice:(id <MKRUPnPDevice>)device{
|
|
|
- libupnp_Stop(device.avTransportUrl);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_Stop(device.avTransportUrl);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)setVolume:(int)volume device:(id <MKRUPnPDevice>)device{
|
|
|
- libupnp_SetZoneVolume(
|
|
|
- device.groupManagementUrl,
|
|
|
- @"urn:schemas-upnp-org:service:GroupManagement:1",
|
|
|
- @"Master",
|
|
|
- volume
|
|
|
- );
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_SetZoneVolume(
|
|
|
+ device.groupManagementUrl,
|
|
|
+ @"urn:schemas-upnp-org:service:GroupManagement:1",
|
|
|
+ @"Master",
|
|
|
+ volume
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)seekToTimeInterval:(NSInteger)timeInterval device:(id <MKRUPnPDevice>)device {
|
|
|
NSString *timeString = [NSString HHmmssFormatStrig:timeInterval];
|
|
|
- libupnp_SetMediaSeek(device.avTransportUrl, timeString);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_SetMediaSeek(device.avTransportUrl, timeString);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (void)clearChannelWithChannelNO:(NSString *)channelNO device:(id <MKRUPnPDevice>)device {
|
|
|
NSString *channelID = [NSString stringWithFormat:@"CHANNEL_UPDATE_%@",channelNO];
|
|
|
NSString *timestamp = [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
|
|
|
- libupnp_SetChannelClear(device.groupManagementUrl, channelID, timestamp);
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ libupnp_SetChannelClear(device.groupManagementUrl, channelID, timestamp);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- (id <MKRRadioResorce>)getPlayingStatusWithDevice:(id <MKRUPnPDevice>)device {
|
|
|
- NSArray *dmrPositionInfo = [[ASControlTools sharedInstanceUPNP] libupnp_GetPositionInfo:device.avTransportUrl];
|
|
|
- if (dmrPositionInfo.count < 16) {
|
|
|
- //执行检查设备是否掉线操作
|
|
|
- }
|
|
|
- MKRRadioResorce *resource = [[MKRRadioResorce alloc] init];
|
|
|
- resource.songName = dmrPositionInfo[2];
|
|
|
- resource.songArtist = dmrPositionInfo[3];
|
|
|
- resource.songAlbumCover = dmrPositionInfo[5];
|
|
|
- resource.songUrl = dmrPositionInfo[7];
|
|
|
- resource.songID = [dmrPositionInfo[16] integerValue];
|
|
|
- NSString *songFrom = dmrPositionInfo[17];
|
|
|
- if ([songFrom containsString:@"//"]) {
|
|
|
- NSArray *arr = [songFrom componentsSeparatedByString:@"//"];
|
|
|
- if (arr.count > 1) {
|
|
|
- songFrom = arr[1];
|
|
|
+
|
|
|
+ wd_playControl_queue(^{
|
|
|
+ NSArray *dmrPositionInfo = [[ASControlTools sharedInstanceUPNP] libupnp_GetPositionInfo:device.avTransportUrl];
|
|
|
+ if (dmrPositionInfo.count < 16) {
|
|
|
+ //执行检查设备是否掉线操作
|
|
|
+ return ;
|
|
|
}
|
|
|
- }
|
|
|
- resource.songFrom = (MKRSourcePlatform)[songFrom integerValue];
|
|
|
- NSString *channelString = dmrPositionInfo[8];
|
|
|
- if (![channelString containsString:@"Unknown:TrackMetaData Incomplete"]) {
|
|
|
- if ([channelString containsString:@"CHANNEL_UPDATE_"]) {
|
|
|
- resource.songChannel = [[channelString componentsSeparatedByString:@"CHANNEL_UPDATE_"].lastObject integerValue];
|
|
|
- } else {
|
|
|
- resource.songChannel = [channelString integerValue];
|
|
|
+// MKRRadioResorce *resource = [[MKRRadioResorce alloc] init];
|
|
|
+ @synchronized (_currentResource) {
|
|
|
+ self.currentResource.songName = dmrPositionInfo[2];
|
|
|
+ self.currentResource.songArtist = dmrPositionInfo[3];
|
|
|
+ self.currentResource.songAlbumCover = dmrPositionInfo[5];
|
|
|
+ self.currentResource.songUrl = dmrPositionInfo[7];
|
|
|
+ self.currentResource.songID = [dmrPositionInfo[16] integerValue];
|
|
|
+ NSString *songFrom = dmrPositionInfo[17];
|
|
|
+ if ([songFrom containsString:@"//"]) {
|
|
|
+ NSArray *arr = [songFrom componentsSeparatedByString:@"//"];
|
|
|
+ if (arr.count > 1) {
|
|
|
+ songFrom = arr[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.currentResource.songFrom = (MKRSourcePlatform)[songFrom integerValue];
|
|
|
+ NSString *channelString = dmrPositionInfo[8];
|
|
|
+ if (![channelString containsString:@"Unknown:TrackMetaData Incomplete"]) {
|
|
|
+ if ([channelString containsString:@"CHANNEL_UPDATE_"]) {
|
|
|
+ self.currentResource.songChannel = [[channelString componentsSeparatedByString:@"CHANNEL_UPDATE_"].lastObject integerValue];
|
|
|
+ } else {
|
|
|
+ self.currentResource.songChannel = [channelString integerValue];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // resource.songLength = [self secondsFromTimeString:dmrPositionInfo[1]];
|
|
|
+ // MKRPlayResourceStatus *status = [MKRPlayResourceStatus new];
|
|
|
+ // status.currentTime = [[self secondsFromTimeString:dmrPositionInfo[10]] integerValue];
|
|
|
+ // status.totalTime = [oneSong.songLength integerValue];
|
|
|
+ NSString *songChannelUid = [NSString stringWithFormat:@"%@-%@-%zd",self.userID,device.deviceUUID,self.currentResource.songChannel];
|
|
|
+ self.currentResource.songChannelUid = songChannelUid;
|
|
|
+ self.currentResource.songFlag = [NSString stringWithFormat:@"%@_%zd_%@",songChannelUid,[dmrPositionInfo[16] integerValue],songFrom];
|
|
|
}
|
|
|
+ });
|
|
|
+
|
|
|
+ return self.currentResource;
|
|
|
+}
|
|
|
+
|
|
|
+- (id<MKRRadioResorce>)currentResource{
|
|
|
+ if (!_currentResource) {
|
|
|
+ _currentResource = [[MKRRadioResorce alloc] init];
|
|
|
+ _currentResource.songName = @"猫王妙播";
|
|
|
+ _currentResource.songArtist = @"Keep radio on!";
|
|
|
}
|
|
|
- // resource.songLength = [self secondsFromTimeString:dmrPositionInfo[1]];
|
|
|
- // MKRPlayResourceStatus *status = [MKRPlayResourceStatus new];
|
|
|
- // status.currentTime = [[self secondsFromTimeString:dmrPositionInfo[10]] integerValue];
|
|
|
- // status.totalTime = [oneSong.songLength integerValue];
|
|
|
- NSString *songChannelUid = [NSString stringWithFormat:@"%@-%@-%zd",self.userID,device.deviceUUID,resource.songChannel];
|
|
|
- resource.songChannelUid = songChannelUid;
|
|
|
- resource.songFlag = [NSString stringWithFormat:@"%@_%@_%@",songChannelUid,resource.songID,songFrom];
|
|
|
- return resource;
|
|
|
+ return _currentResource;
|
|
|
}
|
|
|
|
|
|
- (NSHashTable *)listeners{
|