I'm using a stack view to hold various buttons to go to other view controllers, and one button plays a video. Whenever I press this, I get the following messages but the app works fine and the video plays properly:
CATransformLayer changing property masksToBounds in transform-only layer, will have no effect and changing property allowsGroupBlending in transform-only layer, will have no effect
Any idea? Video plays ok in simulator and on device. I'm using the view controller as player like below, Thanks!
guard let url = Bundle.main.path(forResource: "previewMovie", ofType: "m4v") else{return}
let player = AVPlayer(url: URL(fileURLWithPath: url))
let vc = AVPlayerViewController()
vc.player = player
present(vc, animated: true, completion: nil)
Can I ignore the message as it doesn't look like a warning or an error and considering the video plays and the app works fine? I have to resubmit the app. Thanks!
Yes, ignore it. Nothing's wrong with your code.
Related
I'm capturing one view through AVCaptureSession for Screen Recording.Now I want to record one mp4 video in that view which will play through AVPlayer.Screen Recording is working fine if I set some background color on that particular view but whenever I put video through AVPlayer, its not recording that video although screen records successfully but without mp4 video frame.
I'm using Screen Recording by https://github.com/alskipp/ASScreenRecorder.
Code for playing mp4 video through AVPlayer:
let fileURL = Bundle.main.url(forResource:"file_example_MP4_480_1_5MG", withExtension: "mp4")
let player = AVPlayer(url: fileURL!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = viewToRecord.frame
viewToRecord.layer.addSublayer(playerLayer)
player.play()
In above code viewToRecord is the UIView which I need to record with mp4 video in Screen Recording.
Looking for best possible solutions!!!
I want to share a file using the Share Sheet and have written code that seems to work just fine. However I keep seeing these error messages in the log (using Xcode 11.3)
[ShareSheet] connection invalidated
I have two physical devices I'm testing on; an iPad running iOS 13.1.2 and an iPhone 6 running 11.4. I don't see these messages on the iPhone with the older iOS on it. Both cases the sharing seems to work just fine. Here's the code I'm using using text instead of a file:
let activityViewController = UIActivityViewController(activityItems: ["simple text for test"], applicationActivities: nil)
activityViewController.excludedActivityTypes = [.message, .airDrop]
activityViewController.popoverPresentationController?.barButtonItem = myBarButtonItem
self.present(activityViewController, animated: true, completion: nil)
The message shows up when the share sheet goes away (either because user completes an action, or they tap outside of it to cancel).
Is it safe to ignore these messages? It's just odd that they didn't show up in the older OS but do in the new one.
Edited on 20 Mar 2020: I validated that I was providing a valid source or barButtonItem. I've changed the code to match that where I'm using a UIBarButtonItem and I still see the ShareSheet connection invalidated error.
I got
[ShareSheet] connection invalidated
in the Xcode output log on iOS 13.x, and the share sheet was squished and did not have any buttons in it.
To fix it, assign your sourceView to something more specific than self.view
In my case, I had some UILabels near the top of my view, so I set my sourceView to one of those. For example, in my parent view controller, I had a UILabel named labelCustomerName so I used that:
activityViewController.popoverPresentationController?.sourceView = self.labelCustomerName
For me, it was solved when i added this code, based on Apple developer documentation.
activityViewController.isModalInPresentation = true
By the way, it seems like even if press the close button for the activity it still shows that message.
try this ...
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentsPath.appendingPathComponent(filename)
let activityController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
present(activityController, animated: true, completion: nil)
I have an AVPlayerViewController with a AVPlayer in it, and what I need is that the controls of the player (play, pause, time slider) never hides. Right now after more or less 4 seconds of playing the video the become hidden, and you have to tap the screen to show them again. I haven't been able to find a solution to that.. any ideas? thx!
You can set that by using Key-Value Coding
Swift:
// playerController : AVPlayerViewController
playerController.setValue(false, forKey: "canHidePlaybackControls")
I'm having a similar question to the one this fellow asked a year ago. The difference is that I am unable to fix it.
How can I continuously play background music while switching to different views using swift?
A user answered his question with this:
"You can start and stop your music from AppDelegate... The best way would be to create a MusicPlayer Class, instantiate it in AppDelegate and call start and stop methods in it...
Do you have enough experience to write something like that?
Or should I help you?"
Perhaps I need to edit app delegate? Below is what my viewDidLoad function looks like. It is where I call the audio, but every time I load the view controller it will load and play the song in addition to the first time it was loaded. How can I play a song that will be loaded in the view controller and play while the app is running, regardless of which view I am in?
override func viewDidLoad() {
super.viewDidLoad()
let path = NSBundle.mainBundle().pathForResource("Theme", ofType: "wav")
let soundURL = NSURL(fileURLWithPath: path!)
do {
try theme = AVAudioPlayer(contentsOfURL: soundURL)
theme.prepareToPlay()
} catch let err as NSError {
print(err.debugDescription)
}
// trying to make the music refrain from playing simultaneously
if !theme.playing {
theme.play()
}
theme.numberOfLoops = -1
}
Just put all of that audio player code in your app delegate file within the didFinishLaunchingWithOptions method. That will play the audio file only once when the app first starts and forever until told not to.
I'm trying to learn AVFoundation basics. For now I'm trying to make the simplest custom camera demo possible. The general scheme is to use UIView as a container for AVCaptureVideoPreviewLayer
So I create a previewLayer in the following way:
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
As a following I do this:
previewLayer?.frame = self.imageView.bounds
self.imageView.layer.addSublayer(previewLayer)
captureSession.startRunning()
That's basically it. As a result the captureSession is being run but visually camera preview is misplaced inside the UIView. Please, see the picture below
However, I almost sure I did everything correctly in the storyboard:
I'm sorry I don't know what to add since I'm relatively new in swift. Please let me know if i miss any information required to answer.
So the question is what might be the reason for this kind of UI behaviour?
Thanks in advance.
You need to set view's content mode:
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
First, assuming that you are using Autolayout, make sure your constraints are correct for your views in the storyboard. If you're not using Autolayout, I would recommend doing that first before proceeding.
You'll need to set the frame for your AVCaptureVideoPreviewLayer after adding it to the imageView.
previewLayer.frame = self.imageView.layer.bounds
I think that should take care of it. If you rotate your device, you may need to update the size of the previewLayer in your view controller's viewWillLayoutSubviews.