AirPlay allows users to wirelessly stream content from their iOS device or Mac to devices and accessories compatible with AirPlay.

AirPlay Documentation

Posts under AirPlay tag

43 Posts
Sort by:
Post not yet marked as solved
1 Replies
642 Views
Background We're writing a small recording app - think Voice Memos for the sake of argument. In our app, users should always record with the built-in iPhone microphone. Our Problem Our setup works fine when using just the speakers or in combination with Bluetooth headsets. However, it doesn't work well with Airplay. One of two things can happen: The app records just silence The app crashes when trying to connect the inputNode to the recorderNode (see code below), complaining that IsFormatSampleRateAndChannelCountValid == false Our testing environment is an iPhone Xs, connected to an Airplay 2 compatible Sonos amp. Code We use the following code to set up the AVAudioSession (simplified, without error handling): let session = AVAudioSession.sharedInstance() try session.setCategory(.playAndRecord, options: [.defaultToSpeaker, .allowBluetoothA2DP, .allowAirPlay]) try AVAudioSession.sharedInstance().setActive(true) Every time we record, we configure the audio session to use the built-in mic, and then create a fresh AVAudioEngine. let session = AVAudioSession.sharedInstance() let builtInMicInput = session.availableInputs!.first(where: { $0.portType == .builtInMic }) try session.setPreferredInput(builtInMicInput) let sampleRate: Double = 44100 let numChannels: AVAudioChannelCount = isStereoEnabled ? 2 : 1 let recordingOutputFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: sampleRate, channels: numChannels, interleaved: false)! let engine = AVAudioEngine() let recorderNode = AVAudioMixerNode() // This sets the input volume of those nodes in their destination node (mainMixerNode) to 0. // The raw outputVolume of these nodes remains 1, so when you tap them you still get the samples. // If you set outputVolume = 0 instead, the taps would only receives zeros. recorderNode.volume = 0 engine.attach(recorderNode) engine.connect(engine.mainMixerNode,  to: engine.outputNode,   format: engine.outputNode.inputFormat(forBus: 0)) engine.connect(recorderNode,      to: engine.mainMixerNode,  format: recordingOutputFormat) engine.connect(engine.inputNode,    to: recorderNode,      format: engine.inputNode.inputFormat(forBus: 0)) // and later try engine.start() We install a tap on the recorderNode to save the recorded audio into a file. The tap works fine and is out of scope for this question, and thus not included here. Questions How do we route/configure the audio engine correctly to avoid this problem? Do you have any advice on how to debug such issues in the future? Which variables/states should we inspect? Thank you so much in advance!
Posted Last updated
.
Post not yet marked as solved
1 Replies
631 Views
Hey, I'm writing an app with the possibility to play HLS streams. Some HLS streams I have to play have ad-breaks and I have to display them on the custom view progress bar. To do so I create an instance of AVPlayerItemMetadataCollector and add it to AVPlayerItem instance: swift         let asset = AVURLAsset(url: url)         let item = AVPlayerItem(asset: asset)         let metadataCollector = AVPlayerItemMetadataCollector()         item.add(metadataCollector) It works as expected when I play the stream on the device. When the player receives the manifest with EXT-X-DATERANGE tags the metadataCollector reports the ad-breaks via its delegate's metadataCollector( , didCollect: , indexesOfNewGroups: , indexesOfModifiedGroups: ) method. But suppose, I've started a playback, switched to AirPlay, and closed the player on the device. In this case, the AirPlay device stays connected, so that if I start the playback again (the same item or another), the playback will start at once on AirPlay. The issue in this case is: When the playback starts at once on AirPlay, the AVPlayerItemMetadataCollector instance doesn't report any ad-breaks to its delegate. I've tested this behavior with iPhones (iOS 14.3) and Apple TV 4K (tvOS 14.4) and LG TV with AirPlay 2 support. Is something wrong with AVPlayerItemMetadataCollector configuration or is it an expected behavior or an iOS bug?
Posted Last updated
.
Post not yet marked as solved
1 Replies
502 Views
I have downloaded movies from iTunes to my iPad. I purchased them and downloaded them directly. When I plug the iPad into my TV via HDMI there is no data consumption at all over the WAN source. When I try to Airplay to an Apple TV 4K latest version, the same movie attempts to stream instead of playing from the local file. I am trying to understand why the Apple TV forces the downloaded movie to stream instead of playing from the local copy on the iPad.
Posted Last updated
.