Create view-level services for media playback, complete with user controls, chapter navigation, and support for subtitles and closed captioning using AVKit.

Posts under AVKit tag

200 Posts

Post

Replies

Boosts

Views

Activity

tvOS: How to avoid fast-forwarding in AVPlayerViewController
Due to legal restrictions I need to prevent my app's users from skipping and fast-forwarding the content that is played by AVPlayerViewController. I use playerViewController(:willResumePlaybackAfterUserNavigatedFrom:to:) and playerViewController(:timeToSeekAfterUserNavigatedFrom:to:) delegate methods to control the skipping behaviour. However, those delegate methods are only triggered for skip +/- 10, but not for fast-forwarding/rewinding.  Is there a way to prevent fast-forwarding in addition to skipping in AVPlayerViewController? Here is an example of the code I use: class ViewController: UIViewController {   override func viewDidAppear(_ animated: Bool) {     super.viewDidAppear(animated)     setUpPlayerViewController()   }   private func setUpPlayerViewController() {     let playerViewController = AVPlayerViewController()     playerViewController.delegate = self guard let url = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8") else {       debugPrint("URL is not found")       return     }     let playerItem = AVPlayerItem(url: url)     let player = AVPlayer(playerItem: playerItem)     playerViewController.player = player     present(playerViewController, animated: true) {       playerViewController.player?.play()     }   } } extension ViewController: AVPlayerViewControllerDelegate {   public func playerViewController(_ playerViewController: AVPlayerViewController, willResumePlaybackAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) { // Triggered on skip +/- 10, but not on fast-forwarding/rewinding     print("playerViewController(_:willResumePlaybackAfterUserNavigatedFrom:to:)")   }   public func playerViewController(_ playerViewController: AVPlayerViewController, timeToSeekAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) -> CMTime {     // Triggered on skip +/- 10, but not on fast-forwarding/rewinding     print("playerViewController(_:timeToSeekAfterUserNavigatedFrom:to:)")     return targetTime   } }
2
1
1.6k
Sep ’23
AVPlayer Subtitle Styling
In our application, we play video-on-demand (VOD) content and display subtitles in different languages. The format we prefer for subtitles is WebVTT. We are planning to enhance caption styling (text color, background color, font weight, etc.) in WebVTT files. In our current flow, subtitles and images are loaded in 6-second chunks. Below is an example of one of the subtitle parts we use: WEBVTT X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000
0
0
1k
Sep ’23
how to play back a slow motion video via URL in iOS?
I am trying to support video playback for remote video files in iOS. It works for a regular video, but has a problem with slow motion videos: the slow motion effect is lost. I.e. A slow motion plays back like a regular speed rate video. Here is what I am doing:         AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];         [asset.resourceLoader setDelegate:self.urlDelegate                                     queue:[self.urlDelegate getDispatchQueue]];         AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];         AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];         AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];         controller.player = player;         [player play];         [self presentViewController:controller animated:false completion:^{ <snipped>         }]; Note, the url points to a QuickTime (.MOV) video file on a HTTP(s) server. Again, the above code plays a slow motion video just like a regular video without any slow motions. Is it because AVURLAsset does not support slow motion video? What are I missing to let AVPlayer plays slow motion? I am targeting iOS 12 and above. Thanks!
1
0
1.8k
Aug ’23
AVMutableMetaDataItem cannot assign to value
Hello I am trying to assign some metadata to my AVExportSession so that the output files have the same metadata attached as the AVExportSession. I have tried import AVFoundation import AVKit and a combo of the two. The AVMutableMetaDataItem.value is unable to be set because the compiler will reference NSObject.value property or its NSObject.setValue(forKey:) method I have tried creating a playground and just creating the Mutable Metadata item without the same errors When trying to subclass AVMutableMetaDataItem and trying to override its open var value property, the compiler will then complain the value we are overriding is read-only in reference to its non-mutable counterpart AVMetaDataItem.value Does a radar need to be filled or is there something I am not doing correctly with creating an AVMutableMetaDataItem?
2
0
1.1k
Aug ’23
AVSpeechSynthesisVoice.speechVoices() Includes Voices That Aren't Available after Upgrading iOS
AVSpeechSynthesisVoice.speechVoices() returns voices that are no longer available after upgrading from iOS 16 to iOS 17 (although this has been an issue for a long time, I think). To reproduce: On iOS 16 download 1 or more enhanced voices under “Accessibility > Spoken Content > Voices”. Upgrade to iOS 17 Call AVSpeechSynthesisVoice.speechVoices() and note that the voices installed in step (1) are still present, yet they are no longer downloaded, therefore they don’t work. And there is no property on AVSpeechSynthesisVoice to indicate if the voice is still available or not. This is a problem for apps that allow users to choose among the available system voices. I receive many support emails surrounding iOS upgrades about this issue. I have to tell them to re-download the voices which is not obvious to them. I've created a feedback item for this as well (FB12994908).
1
1
1.1k
Aug ’23
Quicktime Interactivity?
Is it still possible to tutor a QuickTime movie with hyperlinks? I'm building a website and I know at one point you could author a QuickTime movie that supported links inside the video - either to other timestamps in the video or to other web pages. I don't want to use a custom player, I'd prefer to use the system level. I've seen a really amazing example of this on the mobile version of the memory alpha (Star Trek nerds!) website. There is a movie that plays at the top of pages that is fully interactive. Is that still supported? Is it possible to author that way? I'm not making anything insanely complicate, I just thought it would be a nice way to build a website with tools I'm more comfortable working in.
1
0
1.3k
Aug ’23
Progressively supply media data
I'm trying to use the resourceLoader of an AVAsset to progressively supply media data. Unable to because the delegate asks for the full content requestsAllDataToEndOfResource = true. class ResourceLoader: NSObject, AVAssetResourceLoaderDelegate { func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool { if let ci = loadingRequest.contentInformationRequest { ci.contentType = // public.mpeg-4 ci.contentLength = // GBs ci.isEntireLengthAvailableOnDemand = false ci.isByteRangeAccessSupported = true } if let dr = loadingRequest.dataRequest { if dr.requestedLength > 200_000_000 { // memory pressure // dr.requestsAllDataToEndOfResource is true } } return true } } Also tried using a fragmented MP4 created using AVAssetWriter. But didn't work. Please let me know if it's possible for the AVAssetResourceLoader to not ask for the full content?
1
0
957
Aug ’23
ios 15 can't open pictureinpicture using startPictureInPicture
I can use ios16 to display floating windows, but ios15 cannot. Why @try { NSError *error = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeMoviePlayback options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:&amp;error]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionOrientationBack error:&amp;error]; [[AVAudioSession sharedInstance] setActive:YES error:&amp;error]; } @catch ( NSException *exception ) { NSLog( @"AVAudioSession error" ); } self.pipVC = [[AVPictureInPictureController alloc] initWithPlayerLayer:self.playerLayer]; self.pipVC.delegate = self; [self.pipVC setValue:@1 forKey:@"controlsStyle"]; if ( ![self.pipVC isPictureInPictureActive] ) { [self.pipVC startPictureInPicture]; }
0
0
675
Aug ’23
How to intercept HLS Playlist chunk request for CDN token implementation
Hello, We are using HLS for our streaming iOS and tvOS applications. We have DRM protection on our applications but we want add another secure layer which is CDN token. We want to add that CDN token data on header or query parameters. Any of two are applicable at our CDN side. There is a problem at client side. We want to send that token knowledge and refresh at given a time. We add token data using at initial state let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": headers]) and add interceptor with asset.resourceLoader.setDelegate. It works seamlessly. We use AVAssetResourceLoaderDelegate and we can intercept just master playlist and playlists via func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool and we can refresh CDN token data at only playlists. That token data can be at query params or header. It does not matter. For example, #EXTM3U #EXT-X-VERSION:3 #EXTINF:10.0 https://chunk1?cdntoken=A.ts #EXTINF:10.0 https://chunk2?cdntoken=A.ts #EXTINF:10.0 https://chunk3?cdntoken=A.ts #EXTINF:10.0 assume that it is our .m3u8 file for given live video playlist. It has three chunks with cdn token data in query params. If we give that chunks to AVPlayer. It is going to play chunks in order. When we change new cdn token at query params, it effects our chunk Urls and our player stalls. It is because our cdn adds new cdn token knowledge to chunk's Url. It means that our new .m3u8 is going to be like that for next playlist; #EXT-X-VERSION:3 #EXTINF:10.0 https://chunk4?cdntoken=B.ts #EXTINF:10.0 https://chunk5?cdntoken=B.ts #EXTINF:10.0 https://chunk6?cdntoken=B.ts #EXTINF:10.0 Cdn token data is converted to B from A at cdn side and it sends new playlist like that. That's why, our player is going to stall. Is there any way not to player stall with edited chunk url? When we change new cdn token at header. It does not change chunks url like at the first question but AVPlayer does not allow to intercept chunk Urls which means that before callin https://chunk1?cdntoken=A.ts url, i want to intercept and add new cdn token data to header. Is there any way to intercept chunk Urls like intercepting playlist? Thanks for answers in advance
3
0
2.3k
Aug ’23
PictureInPicture with LL-HLS crashes in iOS apps
i am currently showing video by LL-HLS using AVPlayer and AVPictureInPictureController. Video seems to play just fine when using only AVPlayer But whenever the app turns in to PictureInPicture mode it player crashes or stops with emitting below errors. servers m3u8 file contains rendition-report tag and discontinuity tags. Logs about ECN doesnt seem to be critical because other example m3u8 playlist for samples works just fine. the difference with my server and example m3u8 is that, mine supports multi resolution for various bandwith(ABR). ====================================================== errorDate Optional(2023-07-08 14:07:42 +0000) errorStatusCode -15410 errorDomain CoreMediaErrorDomain errorComment Optional("Server should support ECN for Low Latency") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:47 +0000) errorStatusCode -15418 errorDomain CoreMediaErrorDomain errorComment Optional("Dropping out of Low Latency: missing Rendition Report") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:52 +0000) errorStatusCode -12642 errorDomain CoreMediaErrorDomain errorComment Optional("#EXT-X-DISCONTINUITY-SEQUENCE is no longer in Media Playlist") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:52 +0000) errorStatusCode -12642 errorDomain CoreMediaErrorDomain errorComment Optional("Playlist parse error")
0
0
684
Jul ’23
MPNowPlayingInfoCenter not fully available if player playback controls disabled
If I disable playback controls for an AVPlayer (showsPlaybackControls), some feature of MPNowPlayingInfoCenter no longer working. (play/pause, skip forward and backward). I need custom video and audio controls on my AVPlayer in my app, that's why I disabled the iOS playback controls. But I also need the features of the MPNowPlayingInfoCenter. Is there another solution to achieve this?
1
0
1.1k
Jul ’23
Setting the .commonIdentifierDescription in AVPlayerItem's externalMetadata property does not show up in the AVPlayerViewController UI
I am trying to set the .commonIdentifierTitle, .iTunesMetadataTrackSubTitle, .commonIdentifierDescription metadata to an AVPlayerItem's externalMetadata property, but unfortunately only the title and subtitle shown up in the AVPlayerViewController UI. According to the WWDC22 "Create a great video playback experience" video, we are expecting to see description with a chevron should appears. Example code I used is exactly same as outlined in the video: https://developer.apple.com/videos/play/wwdc2022/10147/?time=248 // Setting content external metadata let titleItem = AVMutableMetadataItem() titleItem.identifier = .commonIdentifierTitle titleItem.value = // Title string let subtitleItem = AVMutableMetadataItem() subtitleItem.identifier = .iTunesMetadataTrackSubTitle subtitleItem.value = // Subtitle string let infoItem = AVMutableMetadataItem() infoItem.identifier = .commonIdentifierDescription infoItem.value = // Descriptive info paragraph playerItem.externalMetadata = [titleItem, subtitleItem, infoItem] Could anyone have solutions regarding to this issue or this is a bug in AVPlayerViewController? Thanks
0
3
871
Jul ’23
AVPlayerViewController causing CPU spikes after deallocation
Dear AVKit Engineers, I see a strange bug in AVKit. Even after the viewcontroller hosting AVPlayerViewController is dismissed, I see CPU spiking to over 100% which is caused by some animation code still running after AVPlayerViewController no more exists ([AVMobileChromelessControlsViewController__animateSliderToTintState:duration:completionHandler:]). How does this code continue to run even after AVPlayerViewController is no more? And what can I do to fix it?
0
0
734
Jul ’23
NSTextField frame automatically hugs content when superview is AVPlayerView.contentOverlayView
I need to manually set the frame of a NSTextField, but it seems that when added to AVPlayerView.contentOverlayView the frame gets resized so that it hugs the text. This doesn't happen when the text field is added to a simple NSView instead. Is this a bug? Is there a workaround? class ViewController: NSViewController { override func loadView() { view = NSView() let text = NSTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) text.translatesAutoresizingMaskIntoConstraints = false text.isEditable = false text.backgroundColor = .red let paragraph = NSMutableParagraphStyle() paragraph.alignment = .center text.attributedStringValue = NSAttributedString(string: "asdf", attributes: [.paragraphStyle: paragraph]) view.addSubview(text) // commenting out the following 3 lines solves the issue let playerView = AVPlayerView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) view.addSubview(playerView) playerView.contentOverlayView!.addSubview(text) // uncommenting the following 5 lines also solves the issue, but the wrong text field frame is briefly visible before it resizes to the correct width // DispatchQueue.main.async { // print(text.frame) // text.frame.size.width = 200 // text.removeConstraints(text.constraints) // } } }
0
0
849
Jun ’23
CloudKit initial sync and background audio leads to high CPU app termination
I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer. The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this: ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync). ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected). ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage. Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?
3
0
2.9k
Jun ’23
AVAudioEngine Cannot Create AVAudioFile from URL
I cannot seem to create an AVAudioFile from a URL to be played in an AVAudioEngine. Here is my complete code, following the documentation. import UIKit import AVKit import AVFoundation class ViewController: UIViewController { let audioEngine = AVAudioEngine() let audioPlayerNode = AVAudioPlayerNode() override func viewDidLoad() { super.viewDidLoad() streamAudioFromURL(urlString: "https://samplelib.com/lib/preview/mp3/sample-9s.mp3") } func streamAudioFromURL(urlString: String) { guard let url = URL(string: urlString) else { print("Invalid URL") return } let audioFile = try! AVAudioFile(forReading: url) let audioEngine = AVAudioEngine() let playerNode = AVAudioPlayerNode() audioEngine.attach(playerNode) audioEngine.connect(playerNode, to: audioEngine.outputNode, format: audioFile.processingFormat) playerNode.scheduleFile(audioFile, at: nil, completionCallbackType: .dataPlayedBack) { _ in /* Handle any work that's necessary after playback. */ } do { try audioEngine.start() playerNode.play() } catch { /* Handle the error. */ } } } I am getting the following error on let audioFile = try! AVAudioFile(forReading: url) Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.coreaudio.avfaudio Code=2003334207 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)} I have tried many other .mp3 file URLs as well as .wav and .m4a and none seem to work. The documentation makes this look so easy but I have been trying for hours to no avail. If you have any suggestions, they would be greatly appreciated!
2
0
2.2k
Jun ’23
No audio on device speakers, works fine with headphones / airplay
hi I am having a issue with sound on a network video stream, the stream is loaded by a m3u,. during playback there is no audio from the device, however when using headphones / airplay audio works correctly. the other peculiar thing is the device simulator works fine. this maybe related to airplay working, but I don't know. this is the view handling the playback. Im not sure where the issue is. I can also play the videos fine when embedding the avplayer in its own view. but that looks messy when you have to dismiss a second window when closing the video. #if os(iOS) import SwiftUI import AVKit import MediaPlayer struct iOSVideoLibraryView: View { @ObservedObject var videoLibrary: VideoLibrary @State private var isPlayerDismissed = false let LiveStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] let VODStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] var body: some View { NavigationView { ScrollView { LazyVGrid(columns: LiveStreams, spacing: 20) { ForEach(videoLibrary.videos, id: \.title) { video in if video.type == "LIVE" { Button(action: { isPlayerDismissed = false // Reset the dismissal flag presentVideoPlayer(videoURL: video.referenceURL) }) { VStack { Image(systemName: "play.circle.fill") .font(.system(size: 30)) // icon .foregroundColor(.blue) Text(video.title) .frame(width: 100, height: 50) // title bounds .font(Font.caption) .background(Color.blue) .foregroundColor(.white) .cornerRadius(3) } .frame(width: 70) // main button container .padding() .background(Color.blue.opacity(0.2)) .cornerRadius(10) } } else { // Handle non-LIVE videos } } } .padding() } .navigationBarTitle("Live Streams") } } private func presentVideoPlayer(videoURL: URL) { let playerViewController = CustomAVPlayerViewController() let player = AVPlayer(url: videoURL) playerViewController.player = player player.isMuted = false player.play() DispatchQueue.main.async { playerViewController.modalPresentationStyle = .fullScreen UIApplication.shared.windows.first?.rootViewController?.present(playerViewController, animated: true, completion: nil) } } } class PlayerManager: NSObject, AVPictureInPictureControllerDelegate { static let shared = PlayerManager() func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { // Perform any necessary actions when picture-in-picture starts } func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { // Perform any necessary actions when picture-in-picture stops } func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, failedToStartPictureInPictureWithError error: Error) { // Perform any necessary actions when picture-in-picture fails to start } } class CustomAVPlayerViewController: AVPlayerViewController { let playerManager = PlayerManager.shared let customPlayer = AVPlayer() override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if AVPictureInPictureController.isPictureInPictureSupported() { if let playerItem = customPlayer.currentItem { let playerLayer = AVPlayerLayer(player: customPlayer) playerLayer.videoGravity = .resizeAspectFill let pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer) pictureInPictureController?.delegate = playerManager if let pictureInPictureController = pictureInPictureController, pictureInPictureController.isPictureInPicturePossible { pictureInPictureController.startPictureInPicture() } } } } override func viewDidLoad() { super.viewDidLoad() customPlayer.addObserver(self, forKeyPath: "currentItem", options: .new, context: nil) } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) customPlayer.removeObserver(self, forKeyPath: "currentItem") } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "currentItem" { if let playerItem = customPlayer.currentItem { // Handle player item change } } } } #endif
2
0
1.4k
Jun ’23
Error 16833 and 19152
We have created a hls playback framework and lot of our client's are complaining about this error {"code": -19152, "domain": "CoreMediaErrorDomain", "localizedDescription": "The operation couldn’t be completed. (CoreMediaErrorDomain error -19152 - The operation couldn’t be completed. (CoreMediaErrorDomain error -19152.))", "localizedFailureReason": "", "localizedRecoverySuggestion": ""} We are unable to reproduce this issue on our end but we have data reflecting the same error happening at good rate. Any help/hint is welcome. Thanks
1
0
2.0k
Jun ’23
tvOS: How to avoid fast-forwarding in AVPlayerViewController
Due to legal restrictions I need to prevent my app's users from skipping and fast-forwarding the content that is played by AVPlayerViewController. I use playerViewController(:willResumePlaybackAfterUserNavigatedFrom:to:) and playerViewController(:timeToSeekAfterUserNavigatedFrom:to:) delegate methods to control the skipping behaviour. However, those delegate methods are only triggered for skip +/- 10, but not for fast-forwarding/rewinding.  Is there a way to prevent fast-forwarding in addition to skipping in AVPlayerViewController? Here is an example of the code I use: class ViewController: UIViewController {   override func viewDidAppear(_ animated: Bool) {     super.viewDidAppear(animated)     setUpPlayerViewController()   }   private func setUpPlayerViewController() {     let playerViewController = AVPlayerViewController()     playerViewController.delegate = self guard let url = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8") else {       debugPrint("URL is not found")       return     }     let playerItem = AVPlayerItem(url: url)     let player = AVPlayer(playerItem: playerItem)     playerViewController.player = player     present(playerViewController, animated: true) {       playerViewController.player?.play()     }   } } extension ViewController: AVPlayerViewControllerDelegate {   public func playerViewController(_ playerViewController: AVPlayerViewController, willResumePlaybackAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) { // Triggered on skip +/- 10, but not on fast-forwarding/rewinding     print("playerViewController(_:willResumePlaybackAfterUserNavigatedFrom:to:)")   }   public func playerViewController(_ playerViewController: AVPlayerViewController, timeToSeekAfterUserNavigatedFrom oldTime: CMTime, to targetTime: CMTime) -> CMTime {     // Triggered on skip +/- 10, but not on fast-forwarding/rewinding     print("playerViewController(_:timeToSeekAfterUserNavigatedFrom:to:)")     return targetTime   } }
Replies
2
Boosts
1
Views
1.6k
Activity
Sep ’23
AVPlayer Subtitle Styling
In our application, we play video-on-demand (VOD) content and display subtitles in different languages. The format we prefer for subtitles is WebVTT. We are planning to enhance caption styling (text color, background color, font weight, etc.) in WebVTT files. In our current flow, subtitles and images are loaded in 6-second chunks. Below is an example of one of the subtitle parts we use: WEBVTT X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000
Replies
0
Boosts
0
Views
1k
Activity
Sep ’23
Subtitle Styling does not work on AVPlayer
In our application, we play video-on-demand (VOD) content and display subtitles in different languages.
Replies
0
Boosts
0
Views
678
Activity
Sep ’23
how to play back a slow motion video via URL in iOS?
I am trying to support video playback for remote video files in iOS. It works for a regular video, but has a problem with slow motion videos: the slow motion effect is lost. I.e. A slow motion plays back like a regular speed rate video. Here is what I am doing:         AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];         [asset.resourceLoader setDelegate:self.urlDelegate                                     queue:[self.urlDelegate getDispatchQueue]];         AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];         AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];         AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];         controller.player = player;         [player play];         [self presentViewController:controller animated:false completion:^{ <snipped>         }]; Note, the url points to a QuickTime (.MOV) video file on a HTTP(s) server. Again, the above code plays a slow motion video just like a regular video without any slow motions. Is it because AVURLAsset does not support slow motion video? What are I missing to let AVPlayer plays slow motion? I am targeting iOS 12 and above. Thanks!
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’23
AVMutableMetaDataItem cannot assign to value
Hello I am trying to assign some metadata to my AVExportSession so that the output files have the same metadata attached as the AVExportSession. I have tried import AVFoundation import AVKit and a combo of the two. The AVMutableMetaDataItem.value is unable to be set because the compiler will reference NSObject.value property or its NSObject.setValue(forKey:) method I have tried creating a playground and just creating the Mutable Metadata item without the same errors When trying to subclass AVMutableMetaDataItem and trying to override its open var value property, the compiler will then complain the value we are overriding is read-only in reference to its non-mutable counterpart AVMetaDataItem.value Does a radar need to be filled or is there something I am not doing correctly with creating an AVMutableMetaDataItem?
Replies
2
Boosts
0
Views
1.1k
Activity
Aug ’23
AVSpeechSynthesisVoice.speechVoices() Includes Voices That Aren't Available after Upgrading iOS
AVSpeechSynthesisVoice.speechVoices() returns voices that are no longer available after upgrading from iOS 16 to iOS 17 (although this has been an issue for a long time, I think). To reproduce: On iOS 16 download 1 or more enhanced voices under “Accessibility > Spoken Content > Voices”. Upgrade to iOS 17 Call AVSpeechSynthesisVoice.speechVoices() and note that the voices installed in step (1) are still present, yet they are no longer downloaded, therefore they don’t work. And there is no property on AVSpeechSynthesisVoice to indicate if the voice is still available or not. This is a problem for apps that allow users to choose among the available system voices. I receive many support emails surrounding iOS upgrades about this issue. I have to tell them to re-download the voices which is not obvious to them. I've created a feedback item for this as well (FB12994908).
Replies
1
Boosts
1
Views
1.1k
Activity
Aug ’23
Quicktime Interactivity?
Is it still possible to tutor a QuickTime movie with hyperlinks? I'm building a website and I know at one point you could author a QuickTime movie that supported links inside the video - either to other timestamps in the video or to other web pages. I don't want to use a custom player, I'd prefer to use the system level. I've seen a really amazing example of this on the mobile version of the memory alpha (Star Trek nerds!) website. There is a movie that plays at the top of pages that is fully interactive. Is that still supported? Is it possible to author that way? I'm not making anything insanely complicate, I just thought it would be a nice way to build a website with tools I'm more comfortable working in.
Replies
1
Boosts
0
Views
1.3k
Activity
Aug ’23
Progressively supply media data
I'm trying to use the resourceLoader of an AVAsset to progressively supply media data. Unable to because the delegate asks for the full content requestsAllDataToEndOfResource = true. class ResourceLoader: NSObject, AVAssetResourceLoaderDelegate { func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool { if let ci = loadingRequest.contentInformationRequest { ci.contentType = // public.mpeg-4 ci.contentLength = // GBs ci.isEntireLengthAvailableOnDemand = false ci.isByteRangeAccessSupported = true } if let dr = loadingRequest.dataRequest { if dr.requestedLength > 200_000_000 { // memory pressure // dr.requestsAllDataToEndOfResource is true } } return true } } Also tried using a fragmented MP4 created using AVAssetWriter. But didn't work. Please let me know if it's possible for the AVAssetResourceLoader to not ask for the full content?
Replies
1
Boosts
0
Views
957
Activity
Aug ’23
ios 15 can't open pictureinpicture using startPictureInPicture
I can use ios16 to display floating windows, but ios15 cannot. Why @try { NSError *error = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeMoviePlayback options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:&amp;error]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionOrientationBack error:&amp;error]; [[AVAudioSession sharedInstance] setActive:YES error:&amp;error]; } @catch ( NSException *exception ) { NSLog( @"AVAudioSession error" ); } self.pipVC = [[AVPictureInPictureController alloc] initWithPlayerLayer:self.playerLayer]; self.pipVC.delegate = self; [self.pipVC setValue:@1 forKey:@"controlsStyle"]; if ( ![self.pipVC isPictureInPictureActive] ) { [self.pipVC startPictureInPicture]; }
Replies
0
Boosts
0
Views
675
Activity
Aug ’23
How to intercept HLS Playlist chunk request for CDN token implementation
Hello, We are using HLS for our streaming iOS and tvOS applications. We have DRM protection on our applications but we want add another secure layer which is CDN token. We want to add that CDN token data on header or query parameters. Any of two are applicable at our CDN side. There is a problem at client side. We want to send that token knowledge and refresh at given a time. We add token data using at initial state let asset = AVURLAsset(url: url, options: ["AVURLAssetHTTPHeaderFieldsKey": headers]) and add interceptor with asset.resourceLoader.setDelegate. It works seamlessly. We use AVAssetResourceLoaderDelegate and we can intercept just master playlist and playlists via func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool and we can refresh CDN token data at only playlists. That token data can be at query params or header. It does not matter. For example, #EXTM3U #EXT-X-VERSION:3 #EXTINF:10.0 https://chunk1?cdntoken=A.ts #EXTINF:10.0 https://chunk2?cdntoken=A.ts #EXTINF:10.0 https://chunk3?cdntoken=A.ts #EXTINF:10.0 assume that it is our .m3u8 file for given live video playlist. It has three chunks with cdn token data in query params. If we give that chunks to AVPlayer. It is going to play chunks in order. When we change new cdn token at query params, it effects our chunk Urls and our player stalls. It is because our cdn adds new cdn token knowledge to chunk's Url. It means that our new .m3u8 is going to be like that for next playlist; #EXT-X-VERSION:3 #EXTINF:10.0 https://chunk4?cdntoken=B.ts #EXTINF:10.0 https://chunk5?cdntoken=B.ts #EXTINF:10.0 https://chunk6?cdntoken=B.ts #EXTINF:10.0 Cdn token data is converted to B from A at cdn side and it sends new playlist like that. That's why, our player is going to stall. Is there any way not to player stall with edited chunk url? When we change new cdn token at header. It does not change chunks url like at the first question but AVPlayer does not allow to intercept chunk Urls which means that before callin https://chunk1?cdntoken=A.ts url, i want to intercept and add new cdn token data to header. Is there any way to intercept chunk Urls like intercepting playlist? Thanks for answers in advance
Replies
3
Boosts
0
Views
2.3k
Activity
Aug ’23
PictureInPicture with LL-HLS crashes in iOS apps
i am currently showing video by LL-HLS using AVPlayer and AVPictureInPictureController. Video seems to play just fine when using only AVPlayer But whenever the app turns in to PictureInPicture mode it player crashes or stops with emitting below errors. servers m3u8 file contains rendition-report tag and discontinuity tags. Logs about ECN doesnt seem to be critical because other example m3u8 playlist for samples works just fine. the difference with my server and example m3u8 is that, mine supports multi resolution for various bandwith(ABR). ====================================================== errorDate Optional(2023-07-08 14:07:42 +0000) errorStatusCode -15410 errorDomain CoreMediaErrorDomain errorComment Optional("Server should support ECN for Low Latency") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:47 +0000) errorStatusCode -15418 errorDomain CoreMediaErrorDomain errorComment Optional("Dropping out of Low Latency: missing Rendition Report") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:52 +0000) errorStatusCode -12642 errorDomain CoreMediaErrorDomain errorComment Optional("#EXT-X-DISCONTINUITY-SEQUENCE is no longer in Media Playlist") ====================================================== ====================================================== errorDate Optional(2023-07-08 14:07:52 +0000) errorStatusCode -12642 errorDomain CoreMediaErrorDomain errorComment Optional("Playlist parse error")
Replies
0
Boosts
0
Views
684
Activity
Jul ’23
MPNowPlayingInfoCenter not fully available if player playback controls disabled
If I disable playback controls for an AVPlayer (showsPlaybackControls), some feature of MPNowPlayingInfoCenter no longer working. (play/pause, skip forward and backward). I need custom video and audio controls on my AVPlayer in my app, that's why I disabled the iOS playback controls. But I also need the features of the MPNowPlayingInfoCenter. Is there another solution to achieve this?
Replies
1
Boosts
0
Views
1.1k
Activity
Jul ’23
AVPlayer not working on XCode 14.3
AVPlayer was working on a previous version of XCode, but when XCode updated yesterday, the AVPlayer stopped working in the simulator. Here is the error message: [connection] nw_connection_add_timestamp_locked_on_nw_queue [C2] Hit maximum timestamp count, will start dropping events
Replies
3
Boosts
3
Views
2.1k
Activity
Jul ’23
Setting the .commonIdentifierDescription in AVPlayerItem's externalMetadata property does not show up in the AVPlayerViewController UI
I am trying to set the .commonIdentifierTitle, .iTunesMetadataTrackSubTitle, .commonIdentifierDescription metadata to an AVPlayerItem's externalMetadata property, but unfortunately only the title and subtitle shown up in the AVPlayerViewController UI. According to the WWDC22 "Create a great video playback experience" video, we are expecting to see description with a chevron should appears. Example code I used is exactly same as outlined in the video: https://developer.apple.com/videos/play/wwdc2022/10147/?time=248 // Setting content external metadata let titleItem = AVMutableMetadataItem() titleItem.identifier = .commonIdentifierTitle titleItem.value = // Title string let subtitleItem = AVMutableMetadataItem() subtitleItem.identifier = .iTunesMetadataTrackSubTitle subtitleItem.value = // Subtitle string let infoItem = AVMutableMetadataItem() infoItem.identifier = .commonIdentifierDescription infoItem.value = // Descriptive info paragraph playerItem.externalMetadata = [titleItem, subtitleItem, infoItem] Could anyone have solutions regarding to this issue or this is a bug in AVPlayerViewController? Thanks
Replies
0
Boosts
3
Views
871
Activity
Jul ’23
AVPlayerViewController causing CPU spikes after deallocation
Dear AVKit Engineers, I see a strange bug in AVKit. Even after the viewcontroller hosting AVPlayerViewController is dismissed, I see CPU spiking to over 100% which is caused by some animation code still running after AVPlayerViewController no more exists ([AVMobileChromelessControlsViewController__animateSliderToTintState:duration:completionHandler:]). How does this code continue to run even after AVPlayerViewController is no more? And what can I do to fix it?
Replies
0
Boosts
0
Views
734
Activity
Jul ’23
NSTextField frame automatically hugs content when superview is AVPlayerView.contentOverlayView
I need to manually set the frame of a NSTextField, but it seems that when added to AVPlayerView.contentOverlayView the frame gets resized so that it hugs the text. This doesn't happen when the text field is added to a simple NSView instead. Is this a bug? Is there a workaround? class ViewController: NSViewController { override func loadView() { view = NSView() let text = NSTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) text.translatesAutoresizingMaskIntoConstraints = false text.isEditable = false text.backgroundColor = .red let paragraph = NSMutableParagraphStyle() paragraph.alignment = .center text.attributedStringValue = NSAttributedString(string: "asdf", attributes: [.paragraphStyle: paragraph]) view.addSubview(text) // commenting out the following 3 lines solves the issue let playerView = AVPlayerView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) view.addSubview(playerView) playerView.contentOverlayView!.addSubview(text) // uncommenting the following 5 lines also solves the issue, but the wrong text field frame is briefly visible before it resizes to the correct width // DispatchQueue.main.async { // print(text.frame) // text.frame.size.width = 200 // text.removeConstraints(text.constraints) // } } }
Replies
0
Boosts
0
Views
849
Activity
Jun ’23
CloudKit initial sync and background audio leads to high CPU app termination
I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer. The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this: ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync). ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected). ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage. Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?
Replies
3
Boosts
0
Views
2.9k
Activity
Jun ’23
AVAudioEngine Cannot Create AVAudioFile from URL
I cannot seem to create an AVAudioFile from a URL to be played in an AVAudioEngine. Here is my complete code, following the documentation. import UIKit import AVKit import AVFoundation class ViewController: UIViewController { let audioEngine = AVAudioEngine() let audioPlayerNode = AVAudioPlayerNode() override func viewDidLoad() { super.viewDidLoad() streamAudioFromURL(urlString: "https://samplelib.com/lib/preview/mp3/sample-9s.mp3") } func streamAudioFromURL(urlString: String) { guard let url = URL(string: urlString) else { print("Invalid URL") return } let audioFile = try! AVAudioFile(forReading: url) let audioEngine = AVAudioEngine() let playerNode = AVAudioPlayerNode() audioEngine.attach(playerNode) audioEngine.connect(playerNode, to: audioEngine.outputNode, format: audioFile.processingFormat) playerNode.scheduleFile(audioFile, at: nil, completionCallbackType: .dataPlayedBack) { _ in /* Handle any work that's necessary after playback. */ } do { try audioEngine.start() playerNode.play() } catch { /* Handle the error. */ } } } I am getting the following error on let audioFile = try! AVAudioFile(forReading: url) Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.coreaudio.avfaudio Code=2003334207 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)} I have tried many other .mp3 file URLs as well as .wav and .m4a and none seem to work. The documentation makes this look so easy but I have been trying for hours to no avail. If you have any suggestions, they would be greatly appreciated!
Replies
2
Boosts
0
Views
2.2k
Activity
Jun ’23
No audio on device speakers, works fine with headphones / airplay
hi I am having a issue with sound on a network video stream, the stream is loaded by a m3u,. during playback there is no audio from the device, however when using headphones / airplay audio works correctly. the other peculiar thing is the device simulator works fine. this maybe related to airplay working, but I don't know. this is the view handling the playback. Im not sure where the issue is. I can also play the videos fine when embedding the avplayer in its own view. but that looks messy when you have to dismiss a second window when closing the video. #if os(iOS) import SwiftUI import AVKit import MediaPlayer struct iOSVideoLibraryView: View { @ObservedObject var videoLibrary: VideoLibrary @State private var isPlayerDismissed = false let LiveStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] let VODStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] var body: some View { NavigationView { ScrollView { LazyVGrid(columns: LiveStreams, spacing: 20) { ForEach(videoLibrary.videos, id: \.title) { video in if video.type == "LIVE" { Button(action: { isPlayerDismissed = false // Reset the dismissal flag presentVideoPlayer(videoURL: video.referenceURL) }) { VStack { Image(systemName: "play.circle.fill") .font(.system(size: 30)) // icon .foregroundColor(.blue) Text(video.title) .frame(width: 100, height: 50) // title bounds .font(Font.caption) .background(Color.blue) .foregroundColor(.white) .cornerRadius(3) } .frame(width: 70) // main button container .padding() .background(Color.blue.opacity(0.2)) .cornerRadius(10) } } else { // Handle non-LIVE videos } } } .padding() } .navigationBarTitle("Live Streams") } } private func presentVideoPlayer(videoURL: URL) { let playerViewController = CustomAVPlayerViewController() let player = AVPlayer(url: videoURL) playerViewController.player = player player.isMuted = false player.play() DispatchQueue.main.async { playerViewController.modalPresentationStyle = .fullScreen UIApplication.shared.windows.first?.rootViewController?.present(playerViewController, animated: true, completion: nil) } } } class PlayerManager: NSObject, AVPictureInPictureControllerDelegate { static let shared = PlayerManager() func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { // Perform any necessary actions when picture-in-picture starts } func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { // Perform any necessary actions when picture-in-picture stops } func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, failedToStartPictureInPictureWithError error: Error) { // Perform any necessary actions when picture-in-picture fails to start } } class CustomAVPlayerViewController: AVPlayerViewController { let playerManager = PlayerManager.shared let customPlayer = AVPlayer() override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if AVPictureInPictureController.isPictureInPictureSupported() { if let playerItem = customPlayer.currentItem { let playerLayer = AVPlayerLayer(player: customPlayer) playerLayer.videoGravity = .resizeAspectFill let pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer) pictureInPictureController?.delegate = playerManager if let pictureInPictureController = pictureInPictureController, pictureInPictureController.isPictureInPicturePossible { pictureInPictureController.startPictureInPicture() } } } } override func viewDidLoad() { super.viewDidLoad() customPlayer.addObserver(self, forKeyPath: "currentItem", options: .new, context: nil) } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) customPlayer.removeObserver(self, forKeyPath: "currentItem") } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "currentItem" { if let playerItem = customPlayer.currentItem { // Handle player item change } } } } #endif
Replies
2
Boosts
0
Views
1.4k
Activity
Jun ’23
Error 16833 and 19152
We have created a hls playback framework and lot of our client's are complaining about this error {"code": -19152, "domain": "CoreMediaErrorDomain", "localizedDescription": "The operation couldn’t be completed. (CoreMediaErrorDomain error -19152 - The operation couldn’t be completed. (CoreMediaErrorDomain error -19152.))", "localizedFailureReason": "", "localizedRecoverySuggestion": ""} We are unable to reproduce this issue on our end but we have data reflecting the same error happening at good rate. Any help/hint is welcome. Thanks
Replies
1
Boosts
0
Views
2.0k
Activity
Jun ’23