FDWaveformView icon indicating copy to clipboard operation
FDWaveformView copied to clipboard

How do you embed this in a Swift 'View'

Open zaddok opened this issue 1 year ago • 1 comments

Sorry for the beginner question, but I am trying to work out how to include this in an Xcode 14 Swift 5 view programmatically, but I have the following error:

Static method 'buildExpression' requires that 'FDWaveformView' conform to 'View'

To be clear I am talking about when we build a view like this:

struct ContentView:View {
    ...
    var body: some View {
	VStack {
		Text("Test Audio").font(.largeTitle)
                    FDWaveformView()

Is there a way to do this, or adjust the package so that this is possible?

zaddok avatar May 15 '23 06:05 zaddok

I have partially solved this, The following wrapper allows displaying a waveform back to the user, by creating a wrapper view. It is not yet clear to me how to enable things such as zooming and selecting.

import UIKit
import SwiftUI
import Foundation
import FDWaveformView

struct Wrapper: UIViewRepresentable {
    
    @State var waveform:FDWaveformView = FDWaveformView()

    func makeUIView(context: Context) -> FDWaveformView {
        let frame = CGRect(x: 0, y: 0, width: 300, height: 100)
        //let waveform = FDWaveformView()
        waveform.frame = frame
        return waveform
    }

    func updateAudio(url:URL?) {
        waveform.audioURL = url
    }

    func updateUIView(_ uiView: FDWaveformView, context: Context) {
    }

}

zaddok avatar May 15 '23 06:05 zaddok

Hello, thanks for the question!

This latest version implements this in the Example app. Please see https://github.com/fulldecent/FDWaveformView/blob/f470d434969778ede228b8041c6679bc8ae4f4e3/Example/Sources/ContentView.swift

fulldecent avatar Mar 28 '24 03:03 fulldecent