Code Monkey home page Code Monkey logo

velociplayer's Introduction

VelociPlayer

Welcome to VelociPlayer, Rapptr Labs' iOS audio and video player toolkit.

VelociPlayer is a subclass of AVPlayer which enables rapid development of audio and video players.

Integration Example

This example uses a SwiftUI view:

public struct AudioPlayerView: View {
    @ObservedObject public var player: VelociPlayer

    public var body: some View {
        VStack {
            // Play/Pause Button
            Button {
                player.togglePlayback()
            } label: {
                Image(
                    systemName: player.isPaused ?
                        "play.circle.fill" : 
                        "pause.circle.fill"
                )
            }
            
            HStack {
                Text("\(player.time.seconds)")
                
                Spacer()
                
                Text("\(player.duration.seconds)")
            }
        }
    }
}

You can initialize an instance of VelociPlayer with the URL to your content like so:

let player = VelociPlayer(
    autoPlay: true,
    mediaURL: URL(string: "...")
)

velociplayer's People

Contributors

ethantheinnovator avatar jordanosterberg avatar jayaquino avatar nsarno-rapptr avatar

Stargazers

 avatar Andy Lochan avatar  avatar Anthony Harvey avatar  avatar Nabeel J. avatar Cory McAboy avatar  avatar

Watchers

Drew Johnson avatar Cory McAboy avatar

velociplayer's Issues

No callback for setting mediaURL

I would like to set a new mediaURL and then immediately seek to a time based on the new media's duration. However, the duration sets asynchronously (within the didSet of mediaURL) and therefore seeking doesn't work immediately.

Attempt 1:

        // Fails bc duration == 0
        self.player.mediaURL = url
        let duration = player.duration.seconds
        let seconds = 0.3 * duration
        self.player.seek(to: VPTime(seconds: seconds, preferredTimescale: 1))
        self.player.play()

Attempt 2:

        // Fails within seek(toPercent:) function bc duration == 0
        self.player.mediaURL = url
        self.player.seek(toPercent: 0.3)
        self.player.play()

One idea would be to not set mediaURL directly and instead have a function similar to the initializer.

func updateMedia(autoPlay: Bool, mediaURL: URL?, startTime: VPTime?)

Otherwise, maybe some sort of callback when setting new mediaURL to signify "didFinishSetting"

Seeking without ever pressing play

If seeking, but user never clicked play, player will seek but the player's progress will not publish the updated value because startObservingPlayer() was never called

AVAudioSession unintentionally causes other playbacks to stop

Updates in #29 now call setAVCategory before player is needed/used and the default settings (setCategory, setActive) cause other audio to play playing. (ie. Spotify automatically stops as soon as there's a reference to VelociPlayer).

            try? AVAudioSession.sharedInstance().setCategory(audioCategory, mode: audioMode)
            try? AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
internal func beginPlayerObservationIfNeeded() {
        if timeObserver == nil {
            startObservingPlayer()
            setAVCategory()
        }
    }

Possible solutions:

  1. Call setAVCategory() where it originally was, within play()
  2. Make setAVCategory() public and not automatically set

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.