Implement a play/pause button

Last update: 2023-10-02

You can set up buttons that call TVSDK methods to pause and play the media.

Use the following sample code to implement a play or pause button:

_playPauseButton =
[[UIButton alloc] initWithFrame:CGRectMake(BUTTON_POS_X, BUTTON_POS_Y, BUTTON_SIZE_W, BUTTON_SIZE_H)];
[_playPauseButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[_playPauseButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
[_playPauseButton addTarget:self action:@selector(playTouch:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_playPauseButton];


- (void)playTouch:(id)sender {
    if (self.player.status == PTMediaPlayerStatusPlaying) {
        _playPauseButton.selected = YES;
        [self.player pause];
    else {
        _playPauseButton.selected = NO; [self.player play];

On this page