Code Monkey home page Code Monkey logo

asaudiowaveformview's Introduction

ASAudioWaveformView

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

zoom

Requirements

swift 5.0+

Installation

ASAudioWaveformView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ASAudioWaveformView'

Usage

there are two ways to create waveform view, waveform will adjust to fit the frame automatically

  1. init with frame. completion is Optional

    let wave = ASAudioWaveformView.create(frame: CGRect(x: 0, y: 40, width: 200, height: 100)) { (config) in
        let url = Bundle.main.url(forResource: "test", withExtension: "mp3")
        config.audioURL(url).maxSamplesCount(500).fillColor(.systemTeal)
    } completion: { (empty) in
        print("-->draw Complete ,empty: \(empty)")
    }
  2. if you use Autolayout or set the frame later. completion is Optional

    let wave = ASAudioWaveformView()
    wave.createWaveform { (config) in
            let url = Bundle.main.url(forResource: "test", withExtension: "mp3")
            config.audioURL(url).positionType(.top).fillColor(.green)
    } completion: { (empty) in
        print("-->draw Complete ,empty: \(empty)")
    }

config waveform

    /// config waveform postion, the default is center
    public func positionType(_ type: ASAudioWaveformView.PositionType) -> ASAudioWaveformConfig

    /// config waveform content style, the default is polyline
    public func contentType(_ type: ASAudioWaveformView.ContentType) -> ASAudioWaveformConfig

    /// config waveform fill color, the default is yellow
    public func fillColor(_ color: UIColor) -> ASAudioWaveformConfig

    /// config waveform audio source
    public func audioURL(_ URL: URL?) -> ASAudioWaveformConfig

    /// config max samples count, the default is 1000
    public func maxSamplesCount(_ count: Int) -> ASAudioWaveformConfig
    
    /// Specifies a range of time that may limit the temporal portion of the receiver's asset from which media data will be read.The default value of timeRange is CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity).
    public func timeRange(_ range: CMTimeRange) -> ASAudioWaveformConfig
  1. position type center, content type polyLine

    center

  2. position type top, content type polyLine

    top

  3. position type bottom, content type polyLine

    bottom

  4. position type center, content type singleLine

    single

reload with different audio URL

waveform will adjust to fit the frame automatically

/// Refresh waveform by audio url
public func refreshWaveform(with audioURL: URL?)

Author

Andrew Shen, [email protected]

License

ASAudioWaveformView is available under the MIT license. See the LICENSE file for more info.

asaudiowaveformview's People

Contributors

andrewmika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

1c7 xygkevin

asaudiowaveformview's Issues

Expose wave height property

Hi,

Awesome, thanks for this library!

Can the height of the wave be exposed as a configuration property instead of using an arbitrary value (frame.height * 0.5)?

    func loadWaveformData(from audioURL: URL) {
        loadState.loading = true
        ASAudioWaveformDataFactory.loadAudioWaveformData(from: audioURL, formateSize: (waveformConfig.maxSamplesCount, frame.height * 0.5), timeRange: waveformConfig.timeRange) { (samples, assetData) in
            self.loadState = (true, false)
            self.filteredSamples = samples
            self.drawWaveform()
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.