AirPlay from iOS to tvOS shows black screen

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: nil

This 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]
            
        }
        
    }
Answered by Patrick Koning in 721416022

Sorry, didn't see your respons. It works oke now. I think it was a bug in iOS. In the meantime I added some properties to the nowPlayingInfo:

audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: artist!, MPMediaItemPropertyArtist: title!, MPMediaItemPropertyAlbumTitle: radioName, MPMediaItemPropertyMediaType: MPNowPlayingInfoMediaType.audio.rawValue, MPMediaItemPropertyAssetURL: radioURL!, MPMediaItemPropertyArtwork: radioArtwork, MPNowPlayingInfoPropertyIsLiveStream: true, MPNowPlayingInfoPropertyPlaybackRate: 1.0]

Did you ever figure this out? I'm struggling with this right now.

Accepted Answer

Sorry, didn't see your respons. It works oke now. I think it was a bug in iOS. In the meantime I added some properties to the nowPlayingInfo:

audioInfo.nowPlayingInfo = [MPMediaItemPropertyTitle: artist!, MPMediaItemPropertyArtist: title!, MPMediaItemPropertyAlbumTitle: radioName, MPMediaItemPropertyMediaType: MPNowPlayingInfoMediaType.audio.rawValue, MPMediaItemPropertyAssetURL: radioURL!, MPMediaItemPropertyArtwork: radioArtwork, MPNowPlayingInfoPropertyIsLiveStream: true, MPNowPlayingInfoPropertyPlaybackRate: 1.0]

AirPlay from iOS to tvOS shows black screen
 
 
Q