OCMediaPlayer: UI Component
The OCMediaPlayer
is a customizable Media player view which can be embedded in any SwiftUI views to play Video/ Audio.
The media player will have the standard controls like the media progress, seek options, forward/ rewind, switch to full screen options etc.
There are two types of media files could be played
- From a remote server url (https)
- From a locally bundled media file like .mp4,.mov etc.
Features
- User can pass the Media Source to be loaded in the view along with the styling options for the player.
Parameters:
source
: OCMediaSource Source of the media to be played in the media playerstyle
: OCMediaPlayerStyle, This object gives the look and feel of the media player.
Note on Frame Size
- It is very important to note that while adding this MediaPlayer inside any View, the frame will not be calculated automatically, so the height of the frame has to be specified like in the example below.
struct OCMediaPlayerTemplate: View {
/// Media source for the demo
var mediaSource: OCMediaSource {
let urlString = "https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
return .external(url: urlString)
}
/// Body
var body: some View {
VStack() {
OCMediaPlayer(source: mediaSource)
.frame(maxWidth: .infinity, maxHeight: 210)
.cornerRadius(10)
.padding()
Spacer()
}
}
}