Add a player to your view (iOS v3)
Use the following steps and code examples to add a player to the ViewController.h or ViewController.swift file of your app:
- In ViewController.h or ViewController.swift, create a JWPlayerController object named
player. - Create a JWConfig object named
config. At the minimum, you must define the file property. - Initialize the
playerwith theconfig.
@interface ObjCViewController () @property (nonatomic) JWPlayerController *player; @end @implementation ObjCViewController - (void)viewDidLoad { [super viewDidLoad]; JWConfig *config = [[JWConfig alloc] init]; config.file = @"http://example.com/hls.m3u8"; self.player = [[JWPlayerController alloc] initWithConfig:config]; } - (void)viewDidAppear { [super viewDidAppear]; [self.view addSubview:self.player.view]; } @endclass ViewController: UIViewController { var player: JWPlayerController? override func viewDidLoad() { super.viewDidLoad() let config = JWConfig() config.file = "http://example.com/hls.m3u8" player = JWPlayerController(config: config) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) view.addSubview(player!.view) } }
Updated 11 days ago
Did this page help you?
