Latest 0.1.3
Homepage https://github.com/alexey-savchenko/ASWaveformPlayerView
License MIT
Platforms ios 11.0
Frameworks UIKit, Foundation, Accelerate, AVFoundation
Authors

CI Status
Version
License
Platform

Example

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

Requirements

Swift 4+

Installation

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

pod 'ASWaveformPlayerView'

Description

ASWaveformPlayerView

A UIView subclass that displays waveform of a provided local audio file.

This view has 2 gesture recognizers attached:
1) UITapGestureRecognizer – Play – Pause associated with a view audio file.
2) UIPanGestureRecognizer – Seek audio file to specified position.

There are 3 public properties:

  • normalColor – default color of waveform, fills section of waveform that is yet to be played.
  • progressColor – already played section of waveform fills with this color.
  • allowSpacing – inserts little spacing between bars in waveform.

Usage

Since waveform initialization may fail due to invalid URL or ureadable file you should wrap initialization code in try - catch block.
Example:

import UIKit
import ASWaveformPlayerView

class ViewController: UIViewController {

  let audioURL = Bundle.main.url(forResource: "testAudio", withExtension: "mp3")!

  override func viewDidLoad() {
  super.viewDidLoad()

    do {

      let waveform = try ASWaveformPlayerView(audioURL: audioURL, // URL to local a audio file
                                              sampleCount: 1024, // higher numbers make waveform more detailed
                                              amplificationFactor: 500) // constant that affects height of each 'bar' in waveform

      waveform.normalColor = .lightGray
      waveform.progressColor = .orange
      //with high sampleCount passed to init method to avoid artifacts set this to false
      waveform.allowSpacing = false

      view.addSubview(waveform)

      //ASWaveformPlayerView supports both manual and AutoLayout
      waveform.translatesAutoresizingMaskIntoConstraints = false

      let safeArea = view.safeAreaLayoutGuide

      NSLayoutConstraint.activate([waveform.centerXAnchor.constraint(equalTo: safeArea.centerXAnchor),
                                   waveform.centerYAnchor.constraint(equalTo: safeArea.centerYAnchor),
                                   waveform.heightAnchor.constraint(equalToConstant: 128),
                                   waveform.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor),
                                   waveform.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor)])

    } catch {
      //handle error thrown
      print(error.localizedDescription)
    }
  }
}

Author

Alexey Savchenko, [email protected]

License

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

Latest podspec

{
    "name": "ASWaveformPlayerView",
    "version": "0.1.3",
    "summary": "Audio waveform view with playback functionality.",
    "description": "A UIView subclass that displays waveform of a provided local audio file.nnThis view has 2 gesture recognizers attached:n1) UITapGestureRecognizer - Play - Pause associated with a view audio file.n2) UIPanGestureRecognizer - Seek audio file to specified position.nnThere are 3 public properties:nnnormalColor - default color of waveform, displays on section of waveform that is yet to be played.nprogressColor - already played section of waveform fills with this color.nallowSpacing - inserts little spacing between bars in waveform.",
    "homepage": "https://github.com/alexey-savchenko/ASWaveformPlayerView",
    "screenshots": "https://i.imgur.com/GAKHlxq.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "alexey-savchenko": "[email protected]"
    },
    "source": {
        "git": "https://github.com/alexey-savchenko/ASWaveformPlayerView.git",
        "branch": "master",
        "tag": "0.1.3"
    },
    "social_media_url": "https://twitter.com/Alex_Svch",
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "ASWaveformPlayerView/Classes/**/*",
    "frameworks": [
        "UIKit",
        "Foundation",
        "Accelerate",
        "AVFoundation"
    ],
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This