I have created a simple AVPlayer. (If I didn't create it correctly, please help me fixing it...
相关问题
- SwiftUI: UIImage (QRCode) does not load after call
- Playing audio file while I download it
- AVPlayer doesn't play video until a video from
- In a UIViewControllerRepresentable, how can I pass
- How do you preview a view containing a binding to
相关文章
- SwiftUI ForEach 'identified(by:)' is depre
- SwiftUI automatically scroll to bottom in ScrollVi
- Playing Streaming Video With AVPlayer
- Type of expression is ambiguous without more conte
- SwiftUI - Vertical Centering Content inside Scroll
- NavigationView and NavigationLink on button click
- Programmatically detect dark mode in SwiftUI to di
- dyld: Library not loaded SwiftUI when app runs on
Thanks to Bogdan for the quick answer and for the like to the tutorial!
Here is the code, converted to NSView so it could work for macOS apps...
Here is the struct
PlayerView
:Here is the class, "the meat" like Bogdan said:
Finally you can use
PlayerView()
to add the AVPlayer in thestruct ContentView
.Sure, here's the tutorial, by Chris Mash on Medium.
Basically you embed an
AVPlayerLayer
into a struct conforming toUIViewRepresentable
, something you'll do for anyUIView
component you want to use with SwiftUI.The "meat" of the implementation is done in the
PlayerUIView
class:And then you use it like this: