作者:多米音乐_34216717 | 来源:互联网 | 2023-05-17 21:47
Imbuildingamusicappthatwillhaveafeedofpoststhatcontainurltomusicfiles.Whenacell
I'm building a music app that will have a feed of posts that contain url to music files. When a cell in UITableView becomes fully visible playback of a corresponding music track starts. This is a layout I have now.
我正在构建一个音乐应用程序,其中包含包含音乐文件URL的帖子。当UITableView中的单元格变为完全可见时,将开始播放相应的音乐曲目。这是我现在的布局。
Waveform is being generated by a server and I receive its data as an array of type [Float]. Complete waveform is a UIView that has a bar subviews with a height of a corresponding item from array from a server.
波形由服务器生成,我将其数据作为[Float]类型的数组接收。完整波形是一个UIView,它有一个条形子视图,其高度与服务器阵列中的相应项目相同。
Here is a WaveformPlot Source:
这是一个WaveformPlot来源:
class WaveformPlot: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
//MARK: Populate plot with data from server response
func populateWithData(from dataSet: [Float]){
DispatchQueue.main.async {
var offset: CGFloat = 0
for index in 0..
Source of a player I've implemented.
我实施的玩家的来源。
class StreamMusicPlayer: AVPlayer {
private override init(){
super.init()
}
static var currentItemURL: String?
static var shared = AVPlayer()
static func playItem(musicTrack: MusicTrack) {
StreamMusicPlayer.shared = AVPlayer(url: musicTrack.trackURL)
StreamMusicPlayer.currentItemURL = musicTrack.trackURL.absoluteString
StreamMusicPlayer.shared.play()
}
}
extension AVPlayer {
var isPlaying: Bool {
return rate != 0 && error == nil
}
}
The problem is that it is required to show progress of a track currently playing in a corresponding cell waveform.
问题是需要显示当前在相应的单元波形中播放的轨道的进度。
It has to be similar to this:
它必须与此类似:
What approach should i choose? I'm out of ideas how to implement this. Any help appreciated.
我应该选择什么方法?我没有想法如何实现这一点。任何帮助赞赏。
1 个解决方案