前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios 7.2版本短视频demo在录制后,编辑视频选择音乐crash

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

原创
作者头像
小明同学接音视频
发布2021-03-05 14:11:30
4580
发布2021-03-05 14:11:30
举报
文章被收录于专栏:iOS 音视频接入-TRTC

问题背景

由于原来项目是在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;
  }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题背景
  • 问题原因
  • 解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档