【问题标题】:Create Waves Visualization Video Swift创建 Waves 可视化视频 Swift
【发布时间】:2021-02-06 05:33:27
【问题描述】:

这是我想要做的:

截图来自 6s iPhone。

我一直致力于创建视频波形,我想绘制一个看起来像第一个屏幕截图的波形。我正在使用VIWaveformView Github pod 来绘制波浪。但我很困惑如何绘制相同的波浪。

代码:

@IBOutlet weak var vWmainWave: VIWaveformView!
override func viewDidLoad() {
    super.viewDidLoad()
    vWmainWave.waveformNodeViewProvider = BasicWaveFormNodeProvider(generator: { () -> NodePresentation in
        let view = VIWaveformNodeView()
        view.waveformLayer.strokeColor = UIColor(red:0.86, green:0.35, blue:0.62, alpha:1.00).cgColor
        return view
    }())
    vWmainWave.layoutIfNeeded()
    if let url = Bundle.main.url(forResource: "bulletTrain", withExtension: "mp4") {
        let asset = AVAsset.init(url: url)
        _ = vWmainWave.loadVoice(from: asset, completion: { (asset) in
        })
    }
}

问题:如何显示与原图相同的波浪(第一张截图)?

谁能给我解释一下如何画相同的,我试着画这些波浪,但还没有结果。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: ios swift user-interface beatsmusic soundwaves


    【解决方案1】:

    你可以检查这部分

    var waveformView: VIWaveformView!
    override func viewDidLoad() {
            super.viewDidLoad()
            
            
            view.backgroundColor = UIColor(red:0.10, green:0.14, blue:0.29, alpha:1.00)
            
            setupWaveformView()
            view.addSubview(waveformView)
            
            waveformView.translatesAutoresizingMaskIntoConstraints = false
            waveformView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 15).isActive = true
            waveformView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -15).isActive = true
            waveformView.topAnchor.constraint(equalTo: view.topAnchor, constant: 65).isActive = true
            waveformView.heightAnchor.constraint(equalToConstant: 80).isActive = true
            
            waveformView.layoutIfNeeded()
            if let url = Bundle.main.url(forResource: "Moon River", withExtension: "mp3") {
                let asset = AVAsset.init(url: url)
                _ = waveformView.loadVoice(from: asset, completion: { (asset) in
                })
            }
    }
    

    https://github.com/VideoFlint/VIWaveformView/blob/master/VIWaveformView/ViewController.swift

    【讨论】:

    • 感谢您的回复,但此代码为 .mp3。我已经使用过此代码,但同样的问题不适用于视频
    猜你喜欢
    • 2019-12-30
    • 1970-01-01
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多