ios 7.2版本短视频demo在录制后,编辑视频选择音乐crash

2021-03-05 14:11:30 浏览数 (1)

问题背景

由于原来项目是在7.2版本的demo基础上进行修改的,所以无法升级到8.4,目前在7.2版本会出现选择背景音乐后crash的情况,在8.4的demo上并不会出现这个问题。

问题原因

demo在选择音乐的时候没有将音乐文件的后缀带到路径上面,所以在SDK播放背景音乐的时候崩溃了。

解决方案

更换demo的以下方法即可

代码语言:objective-c复制
- (void)_downloadBGMAction:(TCBGMElement*)current {
  const BOOL needOverride = YES;
  __strong UGCKitBGMHelper* strong = self;
  if(strong != nil){
    if([[_currentEle netUrl] isEqualToString:[current netUrl]]){
      if([_currentTask state] == NSURLSessionTaskStateRunning){
        BGMLog(@"暂停:%@", [current name]);
        [_currentTask suspend];
        return;
      }
      else if([_currentTask state] == NSURLSessionTaskStateSuspended){
        BGMLog(@"恢复:%@", [current name]);
        [_currentTask resume];
        return;
      }
    }
    else{
      if(_currentTask){
        if([_currentTask state] != NSURLSessionTaskStateCompleted){
          [_currentTask cancel];
          [strong.delegate onBGMDownloading:_currentEle percent:0];
        }
        _currentTask = nil;
      }
    }
    NSString* localListPath = nil;
    NSString* url = [current netUrl];

    __block NSString* justName = [current name];
    if (0 == justName.pathExtension.length) {
      NSString *bgmExtension = url.pathExtension.length ? url.pathExtension : @"mp3";
      justName = [justName stringByAppendingPathExtension:bgmExtension];
    }
    if (needOverride) {
      localListPath = [_bgmPath stringByAppendingPathComponent:justName];
    } else {
      justName = [NSString stringWithFormat:@"%@1.%@", [justName stringByDeletingPathExtension], [[current name] pathExtension]];
      localListPath = [_bgmPath stringByAppendingPathComponent:justName];
    }
    __weak __typeof(self) weak = self;
    NSURLSessionDownloadTask* task = [self downloadFile:url dstUrl:localListPath callback:^(float percent, NSString* path){
      __strong UGCKitBGMHelper* strong = weak;
      if(strong){
        dispatch_queue_t queue = strong->_queue;
        if(percent < 0){
          dispatch_async(queue, ^{
            [strong.delegate onBGMDownloadDone:current];
          });
        }
        else{
          TCBGMElement* ele = [strong->_bgmDict objectForKey:[current netUrl]];
          if(path != nil){
            ele.localUrl = [NSString stringWithFormat:@"Documents/bgm/%@", justName];
            ele.isValid = [NSNumber numberWithBool:true];
            dispatch_async(queue, ^{
              [strong.delegate onBGMDownloadDone:ele];
            });
            [strong saveBGMStat:ele];
          }else{
            dispatch_async(queue, ^{
              [weak.delegate onBGMDownloading:ele percent:percent];
            });
          }
        }
      }
    }];
    _currentTask = task;
    _currentEle = current;
  }
}

0 人点赞