完成:

1.在转码页面获取并展示视频的时长、视频文件size、文件名称至UI界面呈现
This commit is contained in:
bluesea 2024-03-12 10:01:23 +08:00
parent 7632ba3312
commit e9c75ce3d6
8 changed files with 66 additions and 13 deletions

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
005580782B9F1525004B9567 /* ZZHHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 005580772B9F1525004B9567 /* ZZHHelper.swift */; };
00B946212B67AC9D00DA668F /* CCSpatialPlayController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */; };
00B946232B67B26D00DA668F /* ddd_video.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 00B946222B67B26D00DA668F /* ddd_video.mp4 */; };
00B946252B67B7DE00DA668F /* CCSpatialPlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */; };
@ -91,6 +92,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
005580772B9F1525004B9567 /* ZZHHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZZHHelper.swift; sourceTree = "<group>"; };
00B946202B67AC9C00DA668F /* CCSpatialPlayController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayController.swift; sourceTree = "<group>"; };
00B946222B67B26D00DA668F /* ddd_video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = ddd_video.mp4; sourceTree = "<group>"; };
00B946242B67B7DE00DA668F /* CCSpatialPlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCSpatialPlayView.swift; sourceTree = "<group>"; };
@ -231,6 +233,7 @@
1E1EA28F2B933C8200A5D5D2 /* VideoWriter.swift */,
00D33BF92B9AB21A00604A44 /* ZZHAVExtension.swift */,
1EE5C5F92B8F97BF00EDFC2F /* SpatialVideoWriter.swift */,
005580772B9F1525004B9567 /* ZZHHelper.swift */,
);
path = Util;
sourceTree = "<group>";
@ -632,6 +635,7 @@
AF2121042B4EA61A00400B7F /* CCMineView.swift in Sources */,
AF21210D2B4EA86700400B7F /* RootData.swift in Sources */,
AF2121092B4EA7E200400B7F /* CCRequestDefine.swift in Sources */,
005580782B9F1525004B9567 /* ZZHHelper.swift in Sources */,
AF2120C32B4E95DA00400B7F /* NSObject+Add.swift in Sources */,
1EE5C5F72B8F973A00EDFC2F /* CCSpatialShootController.swift in Sources */,
1EFB8C782B88E2F600C72119 /* UIColor+CCExtension.swift in Sources */,

View File

@ -320,9 +320,10 @@ class CCHomeController: BaseController, LLCycleScrollViewDelegate {
self.navigationController?.pushViewController(vc, animated: true)
}
//
view.selectedVideoHandler = { url in
view.selectedVideoHandler = { url,asset in
let vc = CCSpatialVideoDisplayController()
vc.sourceVideoURL = url
vc.videoOriginalPHAsset = asset
self.navigationController?.pushViewController(vc, animated: true)
}
@ -413,8 +414,8 @@ extension CCHomeController: TZImagePickerControllerDelegate,UINavigationControll
gotoPhotoTransformVC(data: data, url: nil,asset: asset)
}
//
spaceAlbumPopView.selectedVideoHandler = { [self] url in
gotoVideoTransformVC(url: url)
spaceAlbumPopView.selectedVideoHandler = { [self] url,asset in
gotoVideoTransformVC(url: url,asset: asset)
}
}
@ -429,9 +430,10 @@ extension CCHomeController: TZImagePickerControllerDelegate,UINavigationControll
}
func gotoVideoTransformVC(url:URL?) {
func gotoVideoTransformVC(url:URL?,asset:PHAsset?) {
let vc = VRVideoTransformController()
vc.sourceVideoURL = url
vc.videoOriginalPHAsset = asset
self.navigationController?.pushViewController(vc, animated: true)
}
@ -493,7 +495,7 @@ extension CCHomeController: TZImagePickerControllerDelegate,UINavigationControll
let videoURL = info[.mediaURL] as? URL
print("选择视频 Selected video URL: \(String(describing: videoURL))")
gotoVideoTransformVC(url: videoURL)
gotoVideoTransformVC(url: videoURL,asset: info[.phAsset] as? PHAsset)
// sourceVideoURL = videoURL
// heroAsset1 = AVAsset(url: sourceVideoURL!)

View File

@ -529,9 +529,10 @@ class CCSpatialShootController: BaseController {
self.navigationController?.pushViewController(vc, animated: true)
}
//
spaceAlbumPopView.selectedVideoHandler = { url in
spaceAlbumPopView.selectedVideoHandler = { url,asset in
let vc = CCSpatialVideoDisplayController()
vc.sourceVideoURL = url
vc.videoOriginalPHAsset = asset
self.navigationController?.pushViewController(vc, animated: true)
}

View File

@ -7,7 +7,7 @@
import UIKit
import AVFoundation
import Photos
enum SpatialType : Int {
@ -38,6 +38,7 @@ class CCSpatialVideoDisplayController: BaseController {
var videoOriginalAsset:AVAsset?
var videoTempAsset:AVAsset?
var videoOriginalPHAsset:PHAsset?
//
var sourceVideoURL:URL?
@ -323,6 +324,7 @@ class CCSpatialVideoDisplayController: BaseController {
}else if sender.tag == 201 {
//
let transVC = VRVideoTransformController()
transVC.videoOriginalPHAsset = self.videoOriginalPHAsset
transVC.sourceVideoURL = sourceVideoURL
self.navigationController?.pushViewController(transVC, animated: true)
}else if sender.tag == 202 {

View File

@ -43,6 +43,8 @@ enum Video3DFormat : Int {
class VRVideoTransformController: BaseController {
var heroAsset1:AVAsset?
var videoOriginalPHAsset:PHAsset?
var sourceVideoURL:URL?
// private var myPlayer: AVPlayer!
@ -154,8 +156,10 @@ class VRVideoTransformController: BaseController {
mCenLab1!.textColor = UIColor.hexStringToColor(hexString: "#ffffff")
mCenLab1!.font = UIFont.systemFont(ofSize: 14)
mCenView!.addSubview(mCenLab1!)
mCenLab1!.text = "20240121020131292.MOV"
mCenLab1!.text = "--"
mCenLab1!.text = videoOriginalPHAsset?.value(forKey: "filename") as? String
mCenLab1!.sizeToFit()
if(mCenLab1!.width > mCenView!.width - 140){
mCenLab1!.width = mCenView!.width - 140
}
@ -168,7 +172,13 @@ class VRVideoTransformController: BaseController {
mCenLab2!.textColor = UIColor.hexStringToColor(hexString: "#67617A")
mCenLab2!.font = UIFont.systemFont(ofSize: 12)
mCenView!.addSubview(mCenLab2!)
mCenLab2!.text = "00:00:03 · 10.9 MB"
let durationStr:String = ZZHHelper.formatVideoTime(second: Int(videoOriginalPHAsset?.duration ?? 0))
let ar:PHAssetResource = PHAssetResource.assetResources(for: videoOriginalPHAsset!).first!
let fileSize:Double = ar.value(forKey: "fileSize") as! Double
let videoSize = Double(fileSize) / 1024 / 1024
mCenLab2!.text = String(format: "\(durationStr) · %.1f MB",videoSize)
mCenLab2!.sizeToFit()
if(mCenLab2!.width > mCenView!.width - 140){
mCenLab2!.width = mCenView!.width - 140

View File

@ -106,7 +106,7 @@ class VideoWriter {
}
else {
print("audio 追加还未准备好...")
}
}
else {

View File

@ -0,0 +1,34 @@
//
// ZZHHelper.swift
// SwiftProject
//
// Created by aaa on 2024/3/11.
//
import Foundation
class ZZHHelper {
class func formatVideoTime(second:Int) -> String {
let allTime: Int = second
var hours = 0
var minutes = 0
var seconds = 0
var hoursText = ""
var minutesText = ""
var secondsText = ""
hours = allTime / 3600
hoursText = hours > 9 ? "\(hours)" : "0\(hours)"
minutes = allTime % 3600 / 60
minutesText = minutes > 9 ? "\(minutes)" : "0\(minutes)"
seconds = allTime % 3600 % 60
secondsText = seconds > 9 ? "\(seconds)" : "0\(seconds)"
if hoursText == "00" {
return "\(minutesText):\(secondsText)"
}else{
return "\(hoursText):\(minutesText):\(secondsText)"
}
}
}

View File

@ -31,7 +31,7 @@ class CCSpaceAlbumFliterPopView: UIView {
var photos: [UIImage] = []
var selectedImageHandler: ((Data,PHAsset) -> Void)?
var selectedVideoHandler: ((URL) -> Void)?
var selectedVideoHandler: ((URL,PHAsset) -> Void)?
lazy var menuView: CCPopMenuView = {
//icon
@ -515,12 +515,12 @@ extension CCSpaceAlbumFliterPopView:UICollectionViewDataSource, UICollectionView
if Thread.isMainThread {
self.hide()
self.selectedVideoHandler?(url)
self.selectedVideoHandler?(url,asset)
}else{
DispatchQueue.main.async {
self.hide()
self.selectedVideoHandler?(url)
self.selectedVideoHandler?(url,asset)
}
}
}