Integrate photo, audio, and video content into your apps.

Posts under Media tag

74 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

What is the proper way to handle videos in SwiftData ?
I'm creating an application with swiftui which gets images and videos from the Photos picker then store them with swiftData for later use. I save both images and videos as data with  @Attribute(.externalStorage). But it just seems wrong to me to store the videos that way, they can be several gigabytes in size . What is the correct way to handle something like this ? Is it to store the url and then each time the user wants to see a video save a temporary video ?. If that's the case can anyone show me how this should be done? Any comments appreciated Guillermo
0
0
391
Jun ’24
Event callback issues with MediaSession API and iOS
Hi, I'm working on a web project that uses the MediaSession API to interface with the media notification on iOS. The issue that I'm experiencing occurs after pressing the play button in the media session modal where the session seems to NOT fire the event handler callback and also kill the media session itself. It's a strange behaviour considering that the pause callback works fine. audio_source = new Audio(url); navigator.mediasession.metadata = { ... // Metadata here }; navigator.mediasession.setActionHandler('play', (details) => { audio_source.play(); } ); navigator.mediasession.setActionHandler('pause', (details) => { audio_source.pause(); } );
0
0
406
Jun ’24
Command Center / Dynamic Island missing icons and animations
hello all! I'm setting up a really simple media player in my swiftui app. the code is the following: import AVFoundation import MediaPlayer class AudioPlayerProvider { private var player: AVPlayer init() { self.player = AVPlayer() self.player.automaticallyWaitsToMinimizeStalling = false self.setupAudioSession() self.setupRemoteCommandCenter() } private func setupAudioSession() { do { try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) } catch { print("Failed to set up audio session: \(error.localizedDescription)") } } private func setupRemoteCommandCenter() { let commandCenter = MPRemoteCommandCenter.shared() commandCenter.playCommand.addTarget { [weak self] _ in guard let self = self else { return .commandFailed } self.play() return .success } commandCenter.pauseCommand.addTarget { [weak self] _ in guard let self = self else { return .commandFailed } self.pause() return .success } } func loadAudio(from urlString: String) { guard let url = URL(string: urlString) else { return } let asset = AVAsset(url: url) let playerItem = AVPlayerItem(asset: asset) self.player.pause() self.player.replaceCurrentItem(with: playerItem) NotificationCenter.default.addObserver(self, selector: #selector(self.streamFinished), name: .AVPlayerItemDidPlayToEndTime, object: self.player.currentItem) } func setMetadata(title: String, artist: String, duration: Double) { var nowPlayingInfo = [ MPMediaItemPropertyTitle: title, MPMediaItemPropertyArtist: artist, MPMediaItemPropertyPlaybackDuration: duration, MPNowPlayingInfoPropertyPlaybackRate: 1.0, ] as [String: Any] MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo } @objc private func streamFinished() { self.player.seek(to: .zero) try? AVAudioSession.sharedInstance().setActive(false) MPNowPlayingInfoCenter.default().playbackState = .stopped } func play() { MPNowPlayingInfoCenter.default().playbackState = .playing self.player.play() } func pause() { MPNowPlayingInfoCenter.default().playbackState = .paused self.player.pause() } } pretty scholastic. The code works when called on views. It also shows up within the lock screen / dynamic island (when in background), but here lies the problems: The play/pause button do not appear neither in the Command Center nor in the dynamic island. If I tap on the position these button should show up, the command works. Just the icons are not appearing. the waveform animation does not animate when playing. Many audio apps are working just fine so is my code lacking something. But I don't know why. What is missing? Thanks in advance!
1
0
725
May ’24
RTC Peer connection error when trying to accept live video call in WKWebView ran in Mac Catalyst
I am developing an WKWebView app that runs on both mobile and mac platforms using a react website. Currently, an admin user can send a call request in which the user gets a pop-up to answer. on iOS it works as intended, the user is asked to grant permission to utilize camera and microphone and the user is immediately connected upon accepting, however I never receive the pop-up when running in Mac Catalyst. I have ensured to enable permissions in sandbox settings as well as adding NSCamera and NSMic permissions in the property list. in the safari debugging console I receive this error upon clicking the accept call ReferenceError: Can't find variable: RTCPeerConnection Ive attempted to use the webview callback requestMediaCapturePermissionFor, and this did not seem to trigger on attempting to answer the call. Is this an error on my development end? or is this an issue I should look to the react code for a fix. I appreciate any feedback possible. Thanks.
0
0
516
May ’24
Send Custom Interactive Layout in iMessage Extension
Hi, I am integrating iMessage app where I have audio which I want to send as Message. But My requirement is to send a custom layout with play button on it and by tapping on it I can play/pause audio. Also On tapping on sent message view presentation style changes to expanded while I want to not have any presentation change. I just want to tap on message to play audio, nothing else. recently I tried to make a custom layout and then by taking its screenshot I sent it as image, but issue is I cant make this view interqctive. I can play audio on tap of message but I also want to update the layout of the selected message. func sendCustomViewMessage(url:URL) { let customView = MessageView(frame: CGRect(x: 0, y: 0, width: 150, height: 50)) //CustomView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) // Initialize your custom view customView.audioURL = url let customViewImage = imageFromView(view: customView) // Convert custom view to UIImage let layout = MSMessageTemplateLayout() layout.image = customViewImage // Set the image of the message layout layout.mediaFileURL = url layout.caption = "Firt Message" let message = MSMessage() message.layout = layout message.url = url self.activeConversation?.insert(message, completionHandler: nil) } I am searching since days about this but I couldn't get any appropriate solution, can anyone help me on this?
0
0
357
May ’24
Problem IOS Photo Permission
I'm encountering a problem on some Iphone models with photo gallery authorization. On some devices, the authorization only displays "add photos" and "None". However, for many devices, most of them have "Full access", "Limited access" and "None" authorizations, which means that you can't access the gallery. Example of device affected by the bug: Iphone 11 IOS 17.3. I tested on an emulator with the same version, but it works with all 3 authorizations. In Info.plist , I have the following information: NSCameraUsageDescription The application wants to have access to your camera to help you add photos to your worksites. NSPhotoLibraryAddUsageDescription The application wants access to your photos to help you add photos to your building sites. NSPhotoLibraryUsageDescription The application wants access to your photos to help you add photos to your worksites.
1
0
470
Apr ’24
Mail Privacy Protection (MPP) / Private Relay Question
Hello, we have noticed a change in the last few weeks in how Mail Privacy Protection (MPP) is operating. Specifically, MPP pre-caches images within email newsletters that are protected via Private Relay. The end result of the pre-cacheing is that every image in the newsletter is retrieved from our servers even if the user does not open the newsletter. This has been in place since '21. What we've noticed in the last month or so, is that the amount of pre-cacheing has dropped significantly, on the order of 20-25%. We can compare this with newsletters opened in non-MPP environments to know that email sends are consistent, it is only that pre-cached events seem to have changed. Does anyone know of any changes to the logic of Private Relay / MPP that would impact how it is pre-caching data from email newsletters? Thank you.
0
0
543
Apr ’24
Life Radio Tirol Homepage: Problem with MP3 192kb Elements in Safari only
Hello everyone! Im new to this forum and i have a question about playing mp3 files on our Homepage on apple devices: We have a service section with the latest News, Traffic and Weather on our Site. The problem is, that the mp3 Files can be played, but the player shows 0:00 and is not able to go to the middle or end of the file. This is ONLY on Iphone in our app and on Safari. I am recording the mp3 with ffmpeg. The strange thing is, that there is no Bitrate shown in FIle details, and also no length. The File is auto Recorded with a script.
0
0
385
Apr ’24
SwiftUI PhotosPicker does not work
iOS 17.4.1, iPhone 15 Pro. I pick photos from the user's photo library using: ... .photosPicker(isPresented: $addPhotos, selection: $pickedPhotos, matching: .images) .onChange(of: pickedPhotos) { import(photoItems: pickedPhotos) } The picker UI works ok, but then when I import the photos: private func import(photoItems: [PhotosPickerItem]) { for photoItem in photoItems { Log.debug("picked: \(photoItem)") Task { do { let imageData = try await photoItem.loadTransferable(type: Data.self) guard let imageData else { Log.error("failed to load image data") return } guard let image = UIImage(data: imageData) else { Log.error("failed to create image from data") return } // use image .... } catch { Log.error("failed to load image data: \(error)") } } } } Logging the picked photo gives: PhotosPickerItem(_itemIdentifier: "C7E2F753-43F6-413D-BA42-509C60BE9D77/L0/001", _shouldExposeItemIdentifier: false, _supportedContentTypes: [<_UTCoreType 0x1ebcd1c10> public.jpeg (not dynamic, declared), <_UTCoreType 0x1ebcd1d70> public.heic (not dynamic, declared), <UTType 0x300fe0430> com.apple.private.photos.thumbnail.standard (not dynamic, declared), <UTType 0x300fe03f0> com.apple.private.photos.thumbnail.low (not dynamic, declared)], _itemProvider: <PUPhotosFileProviderItemProvider: 0x303fdff00> {types = ( "public.jpeg", "public.heic", "com.apple.private.photos.thumbnail.standard", "com.apple.private.photos.thumbnail.low" )}) Looks like there's a valid photo? But then the loadTransferable() call fails with: 5C9D59CB-3606-48C1-9B37-1F18D642B3AD grantAccessClaim reply is an error: Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x308244f30 {Error Domain=PFPAssetRequestErrorDomain Code=0 "The operation couldn’t be completed. (PFPAssetRequestErrorDomain error 0.)" UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/36CF50FB-38FC-440E-9662-35C23B5E636C/File%20Provider%20Storage/photospicker/uuid=C7E2F753-43F6-413D-BA42-509C60BE9D77&library=1&type=1&mode=2&loc=true&cap=true.jpeg, NSLocalizedDescription=The operation couldn’t be completed. (PFPAssetRequestErrorDomain error 0.)}}} Error loading public.data: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x3081a2550 {Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x308244f30 {Error Domain=PFPAssetRequestErrorDomain Code=0 "The operation couldn’t be completed. (PFPAssetRequestErrorDomain error 0.)" UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/36CF50FB-38FC-440E-9662-35C23B5E636C/File%20Provider%20Storage/photospicker/uuid=C7E2F753-43F6-413D-BA42-509C60BE9D77&library=1&type=1&mode=2&loc=true&cap=true.jpeg, NSLocalizedDescription=The operation couldn’t be completed. (PFPAssetRequestErrorDomain error 0.)}}}}} 2024-04-03 12:16:07.8010 error PhotosView.import: failed to load image data: importNotSupported [ As usual I rebooted my phone as these things tend to be pretty buggy in iOS, but same error. Note this is not in a simulator which seems to have long standing bugs related to photo picking, this is on a freshly upgraded 17.4.1 device. I can't find any documentation related to these errors and all googling comes up with a few other cases but no solutions. Should this API actually work or is it better to go back to the old UIKit stuff? I use loadTransferable(type: Data.self) as UIImage.self is not Transferable and this hack has seemed to work ok for some months.
4
1
1.3k
Apr ’24
Creating a song using MediaPlayer so it shows up in a playlist, from stored file on device.
I'm trying to accomplish creating a new playlist on device that appears in AppleMusic, and adding into the playlist a selection of MP3s within a small IOS app. Now the MP3's are either a stream of bytes, or a flat file already stored on the device (the app itself generates these - they aren't downloaded, they are created in app, and then stored on the local device) in it's local storage space. The idea is that created tracks can show up in a specific play list on the device. Now, there appears to be some conflict as to what framework I need to use. I've found MPMediaPlayer, which appears to allow me to create a playlist using the GetPlaylist call, although the documentation on this seems pretty sparse and there's not a lot of examples I can find on how to use this? It looks like a UUID is passed in, but there is no documentation on what this UUID is or where it comes from? If I want to create a new Playlist, I presume I need to generate a UUID, and then store that locally in order to be able to access that playlist again later, yes? There's an AddItem call which looks like it's how you add a track to a playlist, but there's no documentation on how you generate an entry. The documentation for this function talks about a Product ID, without describing what the product ID is, or where it needs to come from. Is this a GUID? Is it a name/description? Does it have to be unique? I'm assuming this Product ID refers to that which is being added to the playlist, but the documentation is sadly lacking in terms of explaining what the product ID refers to. Is it a media Item, or is that what is created when whatever entity the Product ID is referring to is added to the playlist? I'm assuming I can create a NSURL of the file that is stored that is actually the MP3 sample, but what I do with that in order to actually add it as a playlist entry is unknown. I'm sure there is a mechanism to do this, it's just not clear what that is. There's a lack of understanding or explanation of what the process is here, and some illumination would be helpful.
1
0
620
Mar ’24
Implementing FairPlayStreaming and getting error code -42671
Hi guys, I'm implementing FairPlay support for a video streaming application. I've managed to get as far as generating the SPC and acquiring a license from the license server. However when it comes to parsing the license (CKC) returned from the server, the FPS module returns error code -42671. Has anyone else faced this before and / or knows what the fix is? I thought passing it the license should be enough unless additional data is required?
0
0
748
Mar ’24
Videos play in low quality when projected on a sphere using VideoMaterial
Is there any way to play panoramic or 360 videos in an immersive space, without using VideoMaterial on a sphere? I've tried using local videos with 4k and 8k quality and all of them look pixelated using this approach. I tried both simulator as well as the real device, and I can't ever get a high-quality playback. If the video is played on a regular 2D player, on the other hand, it shows the expected quality.
0
0
547
Feb ’24
Shazam Video
Hello, I have a music on apple music. When I search this music on Shazam, I want it to appear with a clip like the link I provided below. Is there any way you can help with this? Example: https://www.youtube.com/watch?v=St8smx2q1Ho My Music: https://music.apple.com/us/album/tam-ba%C4%9F%C4%B1ms%C4%B1z-t%C3%BCrkiye/1689395789?i=1689395790 Thanks.
0
0
541
Feb ’24
PHPickerViewController crashing with _PFAssertFailHandler
Hello, we are embedding a PHPickerViewController with UIKit (adding the vc as a child vc, embedding the view, calling didMoveToParent) in our app using the compact mode. We are disabling the following capabilities .collectionNavigation, .selectionActions, .search. One of our users using iOS 17.2.1 and iPhone 12 encountered a crash with the following stacktrace: Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0x9fbc __pthread_kill + 8 1 libsystem_pthread.dylib 0x5680 pthread_kill + 268 2 libsystem_c.dylib 0x75b90 abort + 180 3 PhotoFoundation 0x33b0 -[PFAssertionPolicyCrashReport notifyAssertion:] + 66 4 PhotoFoundation 0x3198 -[PFAssertionPolicyComposite notifyAssertion:] + 160 5 PhotoFoundation 0x374c -[PFAssertionPolicyUnique notifyAssertion:] + 176 6 PhotoFoundation 0x2924 -[PFAssertionHandler handleFailureInFunction:file:lineNumber:description:arguments:] + 140 7 PhotoFoundation 0x3da4 _PFAssertFailHandler + 148 8 PhotosUI 0x22050 -[PHPickerViewController _handleRemoteViewControllerConnection:extension:extensionRequestIdentifier:error:completionHandler:] + 1356 9 PhotosUI 0x22b74 __66-[PHPickerViewController _setupExtension:error:completionHandler:]_block_invoke_3 + 52 10 libdispatch.dylib 0x26a8 _dispatch_call_block_and_release + 32 11 libdispatch.dylib 0x4300 _dispatch_client_callout + 20 12 libdispatch.dylib 0x12998 _dispatch_main_queue_drain + 984 13 libdispatch.dylib 0x125b0 _dispatch_main_queue_callback_4CF + 44 14 CoreFoundation 0x3701c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 15 CoreFoundation 0x33d28 __CFRunLoopRun + 1996 16 CoreFoundation 0x33478 CFRunLoopRunSpecific + 608 17 GraphicsServices 0x34f8 GSEventRunModal + 164 18 UIKitCore 0x22c62c -[UIApplication _run] + 888 19 UIKitCore 0x22bc68 UIApplicationMain + 340 20 WorkAngel 0x8060 main + 20 (main.m:20) 21 ??? 0x1bd62adcc (Missing) Please share if you have any ideas as to what might have caused that, or what to look at in such a case. I haven't been able to reproduce this myself unfortunately.
2
0
648
Sep ’24
PHPickerViewController Disregards Order Photo is Selected
I use a PHPickerViewController for a user to select profile images. I want the order in which the photos were selected, respected. However, whenever I return the selected results, the order in which I selected is not reflected. I've double checked my config, but no solution has worked and would appreciate any guidance that does not involve using a 3rd party! Apple Documentation states simply setting the .selection property to .ordered should respect the user's selected order, but it does not!! documentation //Setup code var config = PHPickerConfiguration() config.selectionLimit = 3 config.filter = .images config.selection = .ordered let picker = PHPickerViewController(configuration: config) picker.delegate = self //Delegate handler func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { guard !results.isEmpty else { picker.dismiss(animated: true) return } self.photos = [] var tempImages: [Int: UIImage] = [:] let dispatchGroup = DispatchGroup() for (index, result) in results.enumerated() { dispatchGroup.enter() // Enter the group result.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] object, error in defer { dispatchGroup.leave() } guard let self = self else { return } if let image = object as? UIImage { tempImages[index] = image } } } dispatchGroup.notify(queue: .main) { [weak self] in guard let self = self else { return } for index in 0..<tempImages.keys.count { if let image = tempImages[index] { self.photos?.append(image) } } } picker.dismiss(animated: true) }
1
0
538
Feb ’24
Motion not available ios 17 live photo
Hello. Does anyone have any ideas on how to work with the new iOS 17 Live Photo? I can save the live photo, but I can't set it as wallpaper. Error: "Motion is not available in iOS 17" There are already applications that allow you to do this - VideoToLive and the like. What should I use to implement this with swift language? Most likely the metadata needs to be changed, but I'm not sure.
0
0
1.2k
Feb ’24
iOS15 h5 video element cannot play video
This is my h5 code: <video id="myVideo" src="xxxapp://***.***.xx/***/***.mp4" style="object-fit:cover;opacity:1;width:100%;height:100%;display:block;possition:absolute;" type="video/mp4"></video> I want to load local large video, so, I use WKURLSchemeHandler. - (void)webView:(WKWebView *)webView startURLSchemeTask:(id<WKURLSchemeTask>)urlSchemeTask { NSURLRequest *request = [urlSchemeTask request]; NSURL *url = request.URL; NSString *urlString = url.absoluteString; NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"***" ofType:@"mp4"]; NSData *videoData = [NSData dataWithContentsOfFile:videoPath options:nil error:nil]; NSURLResponse *response = [[NSURLResponse alloc] initWithURL:url MIMEType:@"video/mp4" expectedContentLength:videoData.length textEncodingName:nil]; [urlSchemeTask didReceiveResponse:response]; [urlSchemeTask didReceiveData:videoData]; [urlSchemeTask didFinish]; } but its not work, data is not nil, but video do not play. I would greatly appreciate it if someone could help me find a solution!! ps: can make it, but we cannot use it due to some reasons.
1
1
874
Feb ’24
Animated AVIF is rendered slowly on Safari
Animated AVIF is rendered slowly on Safari Tested with MacBook pro (16" 2019) and Safari (Version 17.0 - 19616.1.27.211.1) and also on several iPhone models (14, 15 Pro) (over BrowserStack) When using macBook pro (16" 2019) with Chrome (Version 120.0.6099.129) it is rendered OK example for 720p@25FPS: https://res.cloudinary.com/yaronshmueli/image/upload/cases/animated_AVIF_Apple/world_flight_fast_decode_tile_clmn_btiolg.avif
1
2
896
Dec ’23