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:

  1. In ViewController.h or ViewController.swift, create a JWPlayerController object named player.
  2. Create a JWConfig object named config. At the minimum, you must define the file property.
  3. Initialize the player with the config.
@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];
}

@end
class 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)
    }
}