IOS swift avplayer dentro de UiView, ¿cómo puedo hacer que funcione?
Soy nuevo en el uso de AVPlayer para IOS swift y lo hice funcionar correctamente. Sin embargo, me gustaría que el video se reproduzca dentro de una UIView en este momento, el video ocupa toda la página por defecto. He estado intentando algunas cosas y nada funciona aquí es mi código. Tengo otro contenido en esa página, por eso me gustaría el avplayer dentro del UIVIEW que se llamanueva vista y cuando pongo el código debajo me da un error. He estado siguiendo este ejemploPosición AVPlayerLayer en la capa UIView
import UIKit
import AVFoundation
import WebKit
import AVKit
class ExampleTable: UIViewController {
@IBOutlet weak var newView: UIView!
let avPlayerViewController = CustomAVPLayerC()
var playerView: AVPlayer?
var AVLayer: AVPlayerLayer?
override func viewDidAppear(_ animated: Bool) {
let movieURL:NSURL? = NSURL(string: "my url")
playerView = AVPlayer(url: movieURL! as URL)
avPlayerViewController.player = playerView
playerView?.isMuted = true
avPlayerViewController.view.frame = newView.frame
newView.addSubview(avPlayerViewController.view)
addChildViewController(avPlayerViewController)
self.present(self.avPlayerViewController, animated: true) {
self.avPlayerViewController.player?.play()
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Sin embargo, cuando hago el código anterior, aparece este error
2017-08-16 15:55:31.770 Yisly[24335:595275] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <app.ExampleTable: 0x7ff78201a650>.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010aab9b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109dec141 objc_exception_throw + 48
2 UIKit 0x000000010b910e44 -[UIViewController _presentViewController:withAnimationController:completion:] + 5146
3 UIKit 0x000000010c28e165 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 294
4 UIKit 0x000000010c28a0e4 -[_UIViewControllerTransitionContext _runAlongsideCompletions] + 155
5 UIKit 0x000000010c289dbc -[_UIViewControllerTransitionContext completeTransition:] + 118
6 UIKit 0x000000010b8d3b70 -[UITransitionView notifyDidCompleteTransition:] + 251
7 UIKit 0x000000010b8d37e8 -[UITransitionView _didCompleteTransition:] + 1408
8 UIKit 0x000000010b8d5eb8 -[UITransitionView _transitionDidStop:finished:] + 104
9 UIKit 0x000000010b7e6f07 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
10 UIKit 0x000000010b7e7446 -[UIViewAnimationState animationDidStop:finished:] + 136
11 QuartzCore 0x000000010b5ca68e _ZN2CA5Layer23run_animation_callbacksEPv + 306
12 libdispatch.dylib 0x000000010da4f05c _dispatch_client_callout + 8
13 libdispatch.dylib 0x000000010da3040b _dispatch_main_queue_callback_4CF + 411
14 CoreFoundation 0x000000010aa7e909 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x000000010aa44ae4 __CFRunLoopRun + 2164
16 CoreFoundation 0x000000010aa44016 CFRunLoopRunSpecific + 406
17 GraphicsServices 0x000000010f203a24 GSEventRunModal + 62
18 UIKit 0x000000010b75b0d4 UIApplicationMain + 159
19 Yisly 0x0000000105c10117 main + 55
20 libdyld.dylib 0x000000010da9b65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException