Giter VIP home page Giter VIP logo

Comments (12)

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Hey, this is is a feature that probably will be included sometime in the future.
Meanwhile, this is one possible solution:

var player = QueuedAudioPlayer()
player.addItems([
    audioItem1,
    audioItem2,
    audioItem3
]]

player.event.playbackEnd.addListener(self, handlePlaybackEnd)

func handlePlaybackEnd(data: AudioPlayer.PlaybackEndEventData) {
    if data == .playedUntilEnd {
        try? player.previous()
    }
}

This will just step back the queue whenever a track is finished. If you want to enable/disable the repeat function you can just add a boolean and check that whenever a track finishes.

from swiftaudio.

wawilliams003 avatar wawilliams003 commented on May 24, 2024

Thank you for your response, unfortunately, this suggestion doesn't work. The app crashes after playback ends with error:
reason: 'Cannot remove an observer <SwiftAudio.AVPlayerObserver 0x6000035f2840> for the key path "timeControlStatus" from <AVPlayer 0x6000022b8800> because it is not registered as an observer.

audioController.player.event.playbackEnd.addListener(self, handlePlaybackEnd) is added in ViewDidLoad method

This is what I tried

func handlePlaybackEnd(data: AudioPlayer.PlaybackEndEventData) {
       if data == .playedUntilEnd {
          if repeatOn {
               // audioController.player.pause()
          try? audioController.player.previous()
               // audioController.player.play()
        }else {
           try? audioController.player.next()
            }
        }
    }
    ```

from swiftaudio.

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Okay I see. What version of SwiftAudio are you using?

from swiftaudio.

wawilliams003 avatar wawilliams003 commented on May 24, 2024

I am using the latest version.

from swiftaudio.

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Is it happening when the player.previous() is triggered? Or player.next()?

from swiftaudio.

wawilliams003 avatar wawilliams003 commented on May 24, 2024

from swiftaudio.

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Okay, for me the method kinda worked, but it is not optimal. I am gonna tag this as an enhancement since a repeat function is useful, so it will be implemented when I get around to it 👍

from swiftaudio.

wawilliams003 avatar wawilliams003 commented on May 24, 2024

from swiftaudio.

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Thanks, yeah that seems like a good solution for now 👍

from swiftaudio.

wawilliams003 avatar wawilliams003 commented on May 24, 2024

from swiftaudio.

jorgenhenrichsen avatar jorgenhenrichsen commented on May 24, 2024

Nice, good job 👍

from swiftaudio.

JhonnyTawk avatar JhonnyTawk commented on May 24, 2024

@wawilliams003 can you give me pointers how did you add the shuffle and the repeat button?
Thank you

from swiftaudio.

Related Issues (20)

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.