Player public events
Listen to events from player:
You can listen to events of the player through the Notification Centre. There are player events and ad events. Just change the string in notification.userInfo
.
#import "ViewController.h"
#import <BridSDK/BridSDK.h>
@interface ViewController ()
@property (nonatomic) BVPlayer *player;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
player = [[BVPlayer alloc] initWithData:[[BVData alloc] initPlayerID:<int> forVideoID:<int>] forView:<UIView>]
[self setupEventNetworking];
}
- (void)setupEventNetworking {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventWriter:) name:@"PlayerEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventWriter:) name:@"AdEvent" object:nil];
}
- (void) eventWriter:(NSNotification *)notification {
if ([notification.name isEqualToString:@"PlayerEvent"]) {
[self logMessage:(NSString *)notification.userInfo[@"event"]];
}
if ([notification.name isEqualToString:@"AdEvent"]) {
[self logMessage:(NSString *)notification.userInfo[@"ad"]];
}
}
@end
import UIKit
import BridSDK
class ViewController: UIViewController {
var player: BVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
player = BVPlayer(data: BVData(playerID: <Int32>, forVideoID: <Int32>), for: <UIView>)
setupEventNetworking()
}
func setupEventNetworking() {
NotificationCenter.default.addObserver(self, selector: #selector(eventWriter), name:NSNotification.Name(rawValue: "PlayerEvent"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(eventWriter), name:NSNotification.Name(rawValue: "AdEvent"), object: nil)
}
@objc func eventWriter(_ notification: NSNotification) {
if notification.name.rawValue == "PlayerEvent" {
print(notification.userInfo?["event"] as! String)
}
if notification.name.rawValue == "AdEvent" {
print(notification.userInfo?["ad"] as! String)
}
}
}
Player events which can be listened:
sec (player time in second)
Play (player play video)
Pause (player pause video)
Stop (player stop video)
Next (player next video)
Previous (player previous video)
PlayerInitalized (player is initialised)
SetupVideo (video is initialised)
MuteVideo (video is muted)
UnMuteVideo (video is unmuted)
GetVolume (get video volume)
SetVolume (set video volume)
GetCurrentTime (get video current time)
GetDuration (get video duration)
GetCurrentIndex (get current video index from playlist)
GetSource (get video url)
PlayByIndex (play video from playlist by index)
GetPlaylist (get playlist url)
GetVideo (get video url)
SetVideo (set video object data)
SetVideoUrl (set video url)
SetAd (set ad object data)
SetFullscreenON (set player to fullscreen)
SetFullscreenOFF (set player to view)
SliderTouched (progress slider touched)
SliderReleased (progress slider released)
SliderValueChanged (progress slider value changed)
AdIsInProgress (check is ad in progress)
Ad events which can be listened:
adLoaded (parser loaded ad)
adStarted (ad video started)
adFirstQuartile (ad first quartile)
adMidpoint (ad midpoint)
adThird Quartile (ad third quartile)
adComplete (ad complete)
adError (ad return error)
adSkipped (ad skipped)
adPaused (ad paused)
adResume (ad resume)
adTapped (ad tapped)
Updated over 2 years ago