ios - 从表格视图中的另一个视图控制器播放某些歌曲时遇到问题
问题描述
我正在尝试制作一个系统,其中有一张包含歌曲列表的专辑,当我按下歌曲时,它会将它带到播放器视图控制器。像 Apple Music 和 Spotify。这些歌曲在我电脑上的一个文件中。它们已经出现在我的 AlbumSongViewController 的列表中,但是当我按下那首歌并且它转到我的 PlayerViewController 时,我不会播放这首歌。任何帮助,我觉得很卡。
我将在我认为有问题的地方显示代码。如果需要,我会添加更多。
专辑歌曲视图控制器:
var song: [Song] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
retrieveSongs()
}
//Delegate and source for tableview
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return song.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SongsTableViewCell", for: indexPath) as! SongsTableViewCell
cell.mainLabel.text = song[indexPath.row].getName()
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
播放器视图控制器:
var player: Player!
var song: [Song] = []
let indexPath = IndexPath()
override func viewDidLoad() {
super.viewDidLoad()
player = Player()
setSession()
UIApplication.shared.beginReceivingRemoteControlEvents()
becomeFirstResponder()
NotificationCenter.default.addObserver(self, selector: Selector(("handleInterruption")), name: AVAudioSession.interruptionNotification, object: nil)
func tableView(_ tableView: AlbumSongViewController, indexPath: IndexPath) {
player.playStream(fileUrl: "http://127.0.0.1/musicfiles" + song[indexPath.row].getName())
changePlayButton()
}
}
解决方案
问题
问题是牢房里有空间。例如,trial song.mp3
。当它试图从数据库中获取歌曲时,这把事情搞砸了。
解决方案
我忘记了当有空格时它会把事情搞砸。当您将歌曲放入数据库时,请记住您应该这样做,例如,trial_song.mp3
.
推荐阅读
- javascript - 如何使用 onBlur 显示结果?
- php - 基于类别的样式帖子存档博客预览
- java - Jenkins 和 Java 中数据迁移管道的想法
- c# - ScheduleWidget(.net核心版)无法构建MonthlyByDayOfMonth(3)时间表
- vba - Google 应用脚本 - 类型错误:无法从未定义中读取属性“0”。(第 7 行,文件“代码”)
- azure-ad-b2c - Azure AD B2C“setting.retryLimit”不起作用
- spring - 为什么 spring.security.user.name 和密码不适用于通过 Spring Boot 2 使用的 Spring 云配置服务器?
- javascript - 检查所有按钮是否颜色相同,然后显示文本 Javascript
- c# - 使用 SendInput 进行鼠标模拟
- c# - 如何复制网站内容并转换为 .txt 文件 selenium C#