- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的学校项目制作一个音乐播放器应用程序。
当我运行该应用程序时,一切正常,除了当我单击歌曲时它不播放。
请帮我提供详细的解释,以便我修复该应用程序。
代码如下:
import UIKit
import AVFoundation
var songs:[String] = []
var audioPlayer = AVAudioPlayer()
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var myTabelView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return songs.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
cell.textLabel?.text = songs[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
do
{
if let audioPath = Bundle.main.path(forResource: songs[indexPath.row], ofType: ".mp3") {
try audioPlayer = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath) as URL)
}
} catch {
print(error.localizedDescription)
}
}
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
gettingSongName()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func gettingSongName() // Get the names of all the songs
{
let folderUrl = URL(fileURLWithPath: Bundle.main.resourcePath!)
do
{
let songPath = try FileManager.default.contentsOfDirectory(at: folderUrl, includingPropertiesForKeys: nil, options: .skipsHiddenFiles) // Axcess all of the song files
for song in songPath
{
var mySong = song.absoluteString
if mySong.contains(".mp3")
{
let findString = mySong.components(separatedBy: "/")
mySong = (findString[findString.count-1])
mySong = mySong.replacingOccurrences(of: "%20", with: " ")
mySong = mySong.replacingOccurrences(of: ".mp3", with: " ")
songs.append(mySong)
}
}
myTabelView.reloadData()
}
catch
{
}
}
}
最佳答案
您只是初始化audioPlayer而不要求它播放,请尝试在audioPlayer初始化之后将其添加到didSelectRow do block 中
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.play()
audioPlayer.delegate = self
关于ios - 无法在我的音乐播放器应用程序上播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44359975/
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
所以我正在开发一个黑 jack 程序,但我有点卡住了。我会警告大家,我对编程真的很陌生,而且,我正在项目中期......所以有一些松散的结局和未使用的变量,以及一些不必要的逻辑(用于测试),但这就是我
我正在尝试创建一个可用作 OpenGL 测试工具的示例程序。到目前为止,我的那个似乎可以工作,但似乎忽略了通过统一变量 MVPMatrix 传递的 MVP 矩阵。当我添加代码以读回制服并检查它是否确实
感谢您帮助我,这是有关我的代码的部分。 printf("Thank you, now please enter the logic gate"); scanf("%s", &C); if (C ==
public static void ejemplosString(String palabra){ char[] letras = palabra.toCharArray();
所以,我有一个 php 应用程序,通过 cgi 和 nginx 运行。我有一个 .jar 程序,用于在条形码打印机(Zebra)上打印条形码,猜猜看是什么!。 我的 php 应用程序使用 exec()
我遇到的唯一问题是 getAll() 方法,它似乎在 PersonnelController 类中的位置立即运行。我也曾在其他很多地方尝试过,但都没有成功。 setAll() 方法看起来不错,我已经测
我是一名优秀的程序员,十分优秀!