Giter VIP home page Giter VIP logo

aswaveformplayerview's Introduction

ASWaveformPlayerView

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.

aswaveformplayerview's People

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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

aswaveformplayerview's Issues

sampleCount and amplificationFactor is changed based on Audio?

Hey, I am trying to use this Library with server URL my URL is http://18.206.123.150/storage/upload/sounds/2018/12/1545196015Zaalima-(Raees)-(RaagSong.Com).mp3.

for this code

        let waveform = try ASWaveformPlayerView(audioURL: audioURL,
                                                sampleCount: 1024,
                                                amplificationFactor: 500)

Should i need to change sampleCount and amplificationFactor base on Audio URL or this library is working only for local URL?

when i used URL which is given in this project then it works fine but it will not work with Server URL can you please help me?

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.