This package is a Music Player created by SwiftUI.
It plays music in Apple Music in iOS device.
This is a demo video of the sample project.
Xcode 15 iOS 17 or later.
// songs are MPSongItem's list
// MPSongItem is song data that contains MPMediaItem, effect, triming, and so on.
// index is the index of music playback
MusicPlayer.shared.play(items: songs, index: index)
MusicPlayer.shared.pause()
MusicPlayer.shared.next()
MusicPlayer.shared.back()
You can change the playback rate using MusicPlayer.shared.rate
You can bind the value with Slider of SwiftUI.
Slider(value: $musicPlayer.rate, in: musicPlayer.rateOptions.minValue...musicPlayer.rateOptions.maxValue, step: musicPlayer.rateOptions.unit)
To raise or lower the rate value by one step, use following.
// increment rate
MusicPlayer.shared.incrementRate()
// decrement rate
MusicPlayer.shared.decrementRate()
You can change the pitch using MusicPlayer.shared.pitch
You can bind the value with Slider of SwiftUI.
Slider(value: $musicPlayer.pitch, in: musicPlayer.pitchOptions.minValue...musicPlayer.pitchOptions.maxValue, step: musicPlayer.pitchOptions.unit)
To raise or lower the pitch value by one step, use following.
// increment pitch
MusicPlayer.shared.incrementPitch()
// decrement pitch
MusicPlayer.shared.decrementPitch()
You can trim playback.
Below code that trim from a minute to three minutes.
MusicPlayer.shared.playbackTimeRange = 60...180
You can shuffle items.
Below code that change shuffle flg.
MusicPlayer.shared.isShuffle.toggle()
You can repeat items.
Below code that change repeat type.
switch MusicPlayer.shared.repeatType {
case .list:
MusicPlayer.shared.repeatType = .one
case .one:
MusicPlayer.shared.repeatType = .none
case .none:
MusicPlayer.shared.repeatType = .list
}
You can change the current playback time using MusicPlayer.shared.currentTime
To raise or lower the pitch value by one step, use following.
Slider(value: $musicPlayer.currentTime, in: 0...Float(duration), step: 0.1) { isEditing in
if isEditing {
musicPlayer.stopCurrentTimeRendering()
}
else {
musicPlayer.startCurrentTimeRedering()
musicPlayer.setSeek(withPlay: musicPlayer.isPlaying)
}
}
Add it in the latest main branch in Swift Package Manager.
Copyright 2022 Kentaro Tsurumoto.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
link |
Stars: 4 |
Last commit: 1 week ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics