Java教程

短视频源码教程之短视频app制作如何实现合拍功能

本文主要是介绍短视频源码教程之短视频app制作如何实现合拍功能,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

当用户发现比较搞笑的视频时,总是想进行模仿的,在短视频app制作合拍功能之前,我们至少需要两部手机,一部负责播放原视频,一部负责拍摄我们自己,非常不便,而现在,合拍功能应运而生,本篇文章是关于在短视频源码中添加合拍功能的教程。

通过本文,你将可以为自己的短视频app制作合拍功能,代码如下:
一、 短视频合拍功能的实现步骤
1、下载
2、拍摄
3、添加各种效果
4、发布
二、 具体实现步骤的短视频源码:

-(void)downloadVideo:(RKDownType)downType{
    
    NSString *href = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"href_w"]];
    if (downType == RKDownType_Chorus) {
        href = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"href"]];
    }
    href = [PublicObj decrypt:href];
    if (href.length <= 0 || [href containsString:@".m3u8"]) {
        if (downType == RKDownType_Save) {

如果该视频暂不支持合拍和下载,则会显示:

  [MBProgressHUD showError:@"该视频暂不支持下载"];
        }else {
            [MBProgressHUD showError:@"该视频暂不支持合拍"];
        }
        _isDownLoading = NO;
        [self dismiss];
        return;
    }
    NSString *title = [NSString stringWithFormat:@"%@",[_parameterDic valueForKey:@"title"]];
    if (title.length == 0) {
        NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
        NSTimeInterval a=[dat timeIntervalSince1970]*1000;
        NSString *timeString = [NSString stringWithFormat:@"%d", (int)a];
        title = timeString;
    }
    hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
    hud.mode = MBProgressHUDModeAnnularDeterminate;

正在下载视频时显示:“正在下载视频,请稍等”

NSString *showDesText = @"正在下载视频";
    downType == RKDownType_Save ? (showDesText = @"正在下载视频"):(showDesText = @"请稍等...");
    hud.label.text = showDesText;
    //1.创建会话管理者
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    NSURL *url = [NSURL URLWithString:href];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSMutableURLRequest *m_reques = [request mutableCopy];
    [m_reques addValue:h5url forHTTPHeaderField:@"referer"];
    request = [m_reques copy];
    NSURLSessionDownloadTask *download = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
        //hud.progress = downloadProgress.fractionCompleted;
        dispatch_async(dispatch_get_main_queue(), ^{
            hud.progress = downloadProgress.completedUnitCount / downloadProgress.totalUnitCount;
        });     
//监听下载进度
        //completedUnitCount 已经下载的数据大小
        //totalUnitCount     文件数据的中大小
        NSLog(@"%f",1.0 *downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
        
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:response.suggestedFilename];
        NSLog(@"targetPath:%@",targetPath);
        NSLog(@"fullPath:%@",fullPath);
        
        return [NSURL fileURLWithPath:fullPath];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        fullPathsss = filePath;
        NSLog(@"%@",filePath);
        
        if (downType == RKDownType_Save) {
            UISaveVideoAtPathToSavedPhotosAlbum([filePath path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
        }else {
            dispatch_async(dispatch_get_main_queue(), ^{
                _isDownLoading = NO;
                [self dismiss];
                
                if ([PublicObj checkNull:[fullPathsss path]]) {
                    [MBProgressHUD showPop:@"该视频暂不支持合拍"];
                    return ;
                }
                if (self.shareEvent) {
                    self.shareEvent(4, [fullPathsss path]);
                }
            });
        }
        
    }];
    
    //3.执行Task
    [download resume];
    
}
-(void)startCameraPreview {
    if (_cameraPreviewing == NO) {
         //合拍
        if (_recordType == RecordType_Chorus) {
            [[TXUGCRecord shareInstance]setMute:YES];
            [self isChorusEvent];
        }else {
            [self resetUGCConfig:NO];
        }
        [_progressView updateMinTime:MIN_RECORD_TIME andMaxTime:MAX_RECORD_TIME];
       
        [TXUGCRecord shareInstance].recordDelegate = self;
        [TXUGCRecord shareInstance].videoProcessDelegate = self;
        if ([PublicObj checkNull:[common getTISDKKey]]) {
            isTXfiter = YES;
            [[TXUGCRecord shareInstance] setBeautyStyle:0 beautyLevel:[TXBaseBeautyView getBaseWhiteValue] whitenessLevel:[TXBaseBeautyView getBaseWhiteValue] ruddinessLevel:0];
        }else{
            isTXfiter = NO;
            [[TXUGCRecord shareInstance] setBeautyStyle:0 beautyLevel:0 whitenessLevel:0 ruddinessLevel:0];
            
            [[MHSDK shareInstance] init:[PublicObj decrypt:[common getTISDKKey]]];
        }
        [[TXUGCRecord shareInstance] setEyeScaleLevel:0];
        [[TXUGCRecord shareInstance] setFaceScaleLevel:0];
        _cameraPreviewing = YES;
    }
}

以上就是短视频源码实现合拍功能的代码实现方式,欢迎大家在评论区和我讨论,文章声明原创,转载请注明文章来自“云豹科技官方”

这篇关于短视频源码教程之短视频app制作如何实现合拍功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!