Wenn ich auf UIButton
drückte, beginnt Musik. Und wenn ich wieder auf den Knopf drücke, hört die Musik auf. Während der Musikwiedergabe, wenn ich auf eine andere Zellentaste drücke, werden beide Musikstücke abgespielt. Ich habe nicht verstanden, wie ich Musik stoppen kann, die von anderen Zellen spielt, oder mit anderen Worten, nur eine Musikinstanz spielt auf einmal. Auch eine Schaltfläche Bildanimation automatisch auf den Standard-Zustand wie sender.selected = false
Stop Others Ton wenn jemand aus anderen Zellen spielt, wenn UIButton von uitableviewcell gedrückt wird
Bitte kann mir jemand sagen, wie kann ich das tun?
Dank
UIButton connected with CollectionViewCell Class
class RadioCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
let reuseIdentifier = "cell"
var objects = [
["url" : "https://s3.amazonaws.com/kargopolov/BlueCafe.mp3", "image": "1.jpg"],
["url" : "https://s3.amazonaws.com/kargopolov/BlueCafe.mp3", "image": "2.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/02%20-%20Kheech%20Meri%20Photo%20-%20DownloadMing.SE.mp3", "image": "3.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/03%20-%20Bewajah%20-%20DownloadMing.SE.mp3", "image": "4.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/04%20-%20Tera%20Chehra%20-%20DownloadMing.SE.mp3", "image": "5.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/02%20-%20Kheech%20Meri%20Photo%20-%20DownloadMing.SE.mp3", "image": "6.jpg"],
["url" : "http://media.downloadming.se/TEMP/Loveshhuda%20(2015)/01%20-%20Mar%20Jaayen%20-%20DownloadMing.SE.mp3", "image": "5.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/01%20-%20Sanam%20Teri%20Kasam%20-%20DownloadMing.SE.mp3", "image": "7.jpg"],
["url" : "http://2016.downloadming1.com/bollywood%20mp3/Sanam%20Teri%20Kasam%20(2016)/02%20-%20Kheech%20Meri%20Photo%20-%20DownloadMing.SE.mp3", "image": "1.jpg"]]
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.objects.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! RadioCollectionViewCell
let object = objects[indexPath.row]
cell.url = object["url"]!
cell.img.image = UIImage(named: object["image"]!)
return cell
}
}
In meiner UICollectionViewCell
Klasse
class RadioCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var img: UIImageView!
var url : String!
var playerItem:AVPlayerItem?
var player:AVPlayer?
@IBAction func audioControlButtonAction(sender: UIButton) {
let nurl = NSURL(string: "\(url)")!
playerItem = AVPlayerItem(URL: nurl)
player=AVPlayer(playerItem: playerItem!)
if sender.selected == false {
player!.play()
sender.selected = true
}else
{
player?.pause()
sender.selected = false
}
}
}
Aber wenn ich auf mehr als eine Zelle drückte, begannen alle gleichzeitig Musik zu spielen. Ich will zu einer Zeit eine Zelle spielen Musik und ich möchte, wenn ich auf eine andere Zelle gedrückt gedrückten Zelle Musik wird automatisch stoppen und spielen derzeit Cell-Musik, wie dieser Player [https://github.com/marsluca/AudioPlayer] Dies ist Mein Projekt https://drive.google.com/file/d/0B29ka7gbDAYxSkNTdENabzB6UDA/view – ZAFAR007
@ ZAFAR007 hier funktioniert Code. https://drive.google.com/open?id=0B7pt8RzeP7M-UElLZGdSaFlovWM – ivarun
Vielen Dank, Sie haben mein Problem gelöst In wenigen Minuten :-) – ZAFAR007