Posts

Post not yet marked as solved
2 Replies
236 Views
Are there more developers noticing that metadata is not working on iOS 16 beta 1 and 2? Both possible solutions are not working: observeValue for key "timedMetadata" and AVPlayerItemMetadataOutputPushDelegate. The code I produced works fine on iOS 16 in the simulator, but not on a real device (iPhone XR).
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.4k Views
When I stream a audio-stream from iOS to tvOS it works, but shows the black screen (mirrorring or video screen I think). What do I have to do to tell tvOS that it's audio and therefore it shows the title, artist and image in the left top corner?I use AVPlayer (this is my ViewDidLoad)://0. Become first responder UIApplication.shared.becomeFirstResponder() //1. Set up the session radioAudioSession = AVAudioSession.sharedInstance() NotificationCenter.default.addObserver(self, selector: #selector(AVAudioSessionInterruption(_:)), name: NSNotification.Name.AVAudioSessionInterruption, object: nil) //2. Choose and set category do {try radioAudioSession.setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, routeSharingPolicy: .longForm)} catch {print("An Error occured setting catergory the audio session: \(error)")} do {try radioAudioSession.setActive(true, with: [])} catch {print("An Error occured activating the audio session: \(error)")} //3. Set AVPlayer radioAVPlayer = AVPlayer.init(playerItem: radioAVPlayerItem) //4. Handle interruptions -> zie @objc func AVAudioSessionInterruption ... radioAVPlayerItem.addObserver(self, forKeyPath: "timedMetadata", options: NSKeyValueObservingOptions(), context: nil) radioAVPlayer.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions(), context: nilThis is my update-function for NowPlayingInfo:func updateNowPlayingInfo (withRadiostation: [String], title: String?, artist: String?) { //bij title en artist = nil dan is er geen songinformatie beschikbaar in de stream let radioName = withRadiostation[0] let radioSlogan = withRadiostation[1] radioURL = URL.init(string: withRadiostation[2]) let radioImage = UIImage(named: withRadiostation[3])! nowPlaying.text = radioName let radioArtwork = MPMediaItemArtwork.init(boundsSize: radioImage.size, requestHandler: { (size) -> UIImage in return radioImage}) if title == nil || artist == nil || (title?.isEmpty)! || (artist?.isEmpty)! { //MPMediaItemPropertyAssetURL: radioURL! audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: radioName, MPMediaItemPropertyArtist: radioSlogan, MPNowPlayingInfoPropertyIsLiveStream: true, MPMediaItemPropertyMediaType: MPNowPlayingInfoMediaType.audio.rawValue, MPMediaItemPropertyArtwork: radioArtwork] } else { //MPMediaItemPropertyAssetURL: radioURL! audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: title as Any, MPMediaItemPropertyArtist: artist as Any, MPNowPlayingInfoPropertyIsLiveStream: true, MPMediaItemPropertyMediaType: MPNowPlayingInfoMediaType.audio.rawValue, MPMediaItemPropertyArtwork: radioArtwork] } }
Posted Last updated
.
Post marked as solved
1 Replies
2.1k Views
I build an app for tvOS but somehow I'n not able to add a working target to a button within a collectionview.Who can help me out? I think it has something to do with adding a subview. All radioStationTiles are presented. I can browse from left to right and back but pussing one of the buttons wont work. I looks like I can select it. override func viewDidLoad() { super.viewDidLoad() collectionView.delegate = self collectionView.dataSource = self }public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return radioStations.count } public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "radioStation", for: indexPath) as! CollectionViewCell let radioStation = radioStations[indexPath.row] let radioStationName = radioStation[0] let radioStationSlogan = radioStation[1] let radioStationURL = radioStation[2] let radioStationTegel = radioStation[3] cell.radioButton.setBackgroundImage(UIImage(named: "tegelAchtergrondWhite (250x250).png"), for: UIControlState.normal) cell.radioButton.setBackgroundImage(UIImage(named: "tegelAchtergrondBlue (250x250).png"), for: UIControlState.highlighted) cell.radioButton.setBackgroundImage(UIImage(named: "tegelAchtergrondBlue (250x250).png"), for: UIControlState.focused) cell.radioButton.setBackgroundImage(UIImage(named: "tegelAchtergrondBlack (250x250).png"), for: UIControlState.selected) cell.radioButton.isEnabled = true cell.radioButton.isUserInteractionEnabled = true cell.radioButton.adjustsImageWhenHighlighted = true cell.radioButton.setImage(UIImage(named: radioStationTegel), for: UIControlState.normal) cell.radioButton.tag = indexPath.row cell.radioButton.addTarget(cell.radioButton, action: #selector(selectRadiostation(sender:)), for: UIControlEvents.touchUpInside) return cell } @objc func selectRadiostation(sender: UIButton) { / print("play") }
Posted Last updated
.
Post marked as solved
6 Replies
1.5k Views
Somehow I'm not getting one aspect of xCode working on a mediaplayer.When timedMetadata is changed the func is executed. I works for audioInfo.nowPlayingInfo. But when I try to update a UILabel on the screen to set the title and artist an error occurs. Updating the UILabel after pressing a button (pushButton) works. Same code. Different results.override func observeValue(forKeyPath: String?, of: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if forKeyPath != "timedMetadata" { return } let data: AVPlayerItem = of as! AVPlayerItem for item in data.timedMetadata! { if item.commonKey!.rawValue == "title" { if let title = item.stringValue, !title.isEmpty { let splitArray = title.components(separatedBy: " - ") artiest = splitArray[0] titel = splitArray[1] } else { titel = "Delta Radio" artiest = "Muziek zonder flauwekul!" } } } / / updateMetaData = true audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: titel, MPMediaItemPropertyArtist:artiest, MPMediaItemPropertyAssetURL: deltaRadioURL!]; updateTitleArtist() } @IBAction func pushButton(_ sender: Any) { self.artiestLabel.text = titel + " / " + artiest } func updateTitleArtist() { self.artiestLabel.text = titel + " / " + artiest updateMetaData = false }I searched and read about threads. Tried it, but it won't work. Read about programmacilly making a UILabel. Tried it, but it won't work.Who can help me out? I think I do not grasp some basic concept of xCode?
Posted Last updated
.