Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reads an audio file and displays the waveform

License

NotificationsYou must be signed in to change notification settings

fulldecent/FDWaveformView

Repository files navigation

FDWaveformView displays audio waveforms in Swift apps so users can preview audio, scrub, and pick positions with ease.

Usage

Add anFDWaveformView programmatically, then load audio. If your file is missing an extension, see theStack Overflow answer on AVURLAsset without extensions.

letthisBundle=Bundle(for:type(of:self))leturl= thisBundle.url(forResource:"Submarine", withExtension:"aiff")self.waveform.audioURL= url

Waveform overview showing loaded audio

Features

Highlight playback

Highlight a portion of the waveform to show progress.

self.waveform.highlightedSamples=0..<(self.waveform.totalSamples/2)

Waveform with highlighted progress

Zoom for detail

Render only the visible portion while progressively adding detail as you zoom.

self.waveform.zoomSamples=0..<(self.waveform.totalSamples/4)

Zoomed waveform segment

Gesture control

Allow scrubbing, stretching, and scrolling with built-in gestures.

self.waveform.doesAllowScrubbing=trueself.waveform.doesAllowStretch=trueself.waveform.doesAllowScroll=true

Gesture-driven waveform interaction

Animated updates

Animate property changes for smoother UI feedback.

UIView.animate(withDuration:0.3){letrandomNumber=arc4random()%self.waveform.totalSamplesself.waveform.highlightedSamples=0..< randomNumber}

Animated waveform highlight change

Rendering quality

  • Antialiased waveforms draw extra pixels to avoid jagged edges.
  • Autolayout-driven size changes trigger re-rendering to prevent pixelation.
  • Supports iOS 15+ and visionOS 1.0+.
  • Includes unit tests running on GitHub Actions.

Installation

Use Swift Package Manager: in Xcode choose File > Swift Packages > Add Package Dependency and point to this repository. Legacy installation options are available if needed.

API

Following is the complete API for this module:

  • FDWaveformView (open class, subclass ofUIView)

    • init() (public init) default initializer
    • delegate: FDWaveformViewDelegate? (open var, get/set) delegate for loading and rendering callbacks
    • audioURL: URL? (open var, get/set) audio file to render asynchronously
    • totalSamples: Int (open var, get) sample count of the loaded asset
    • highlightedSamples: CountableRange<Int>? (open var, get/set) range tinted withprogressColor
    • zoomSamples: CountableRange<Int> (open var, get/set) range currently displayed
    • doesAllowScrubbing: Bool (open var, get/set) enable tap and pan scrubbing
    • doesAllowStretch: Bool (open var, get/set) enable pinch-to-zoom
    • doesAllowScroll: Bool (open var, get/set) enable panning across the waveform
    • wavesColor: UIColor (open var, get/set) tint for the base waveform image
    • progressColor: UIColor (open var, get/set) tint for the highlighted waveform
    • loadingInProgress: Bool (open var, get) indicates async load in progress
  • FDWaveformViewDelegate (@objc public protocol)

    • waveformViewWillRender(_ waveformView: FDWaveformView) (optional)
    • waveformViewDidRender(_ waveformView: FDWaveformView) (optional)
    • waveformViewWillLoad(_ waveformView: FDWaveformView) (optional)
    • waveformViewDidLoad(_ waveformView: FDWaveformView) (optional)
    • waveformDidBeginPanning(_ waveformView: FDWaveformView) (optional)
    • waveformDidEndPanning(_ waveformView: FDWaveformView) (optional)
    • waveformDidEndScrubbing(_ waveformView: FDWaveformView) (optional)

A couple other things are exposed that we do not consider public API:

  • FDWaveformView (implementsUIGestureRecognizerDelegate)
    • gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) -> Bool

Testing

Find an available simulator:

xcrun simctl list devices available| grep iPhone

Build and test using a simulator ID from the output:

# Build the libraryxcodebuild build -scheme FDWaveformView -destination'id=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'# Run unit testsxcodebuildtest -scheme FDWaveformView -destination'id=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'# Build the Example app (requires a newer iOS simulator)cd Examplexcodebuild build -scheme Example -destination'id=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

Contributing

About

Reads an audio file and displays the waveform

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors23

Languages


[8]ページ先頭

©2009-2025 Movatter.jp