Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS AVPlayer Play/Pause button issue

Tags:

ios

avplayer

I am using AVPlayer to play a live stream from the Internet using the following code :

    NSString *u = @"http://192.192.192.192:8036";
NSURL *url = [NSURL URLWithString:u];
radiosound = [[AVPlayer alloc] initWithURL:url];
    [radiosound play]; 

And I have one button play :

[radiosound play]; 

and Pause :

[radiosound pause]; 

My issue is that I want to use only one button Play/Pause, but when I am using this code

if (radiosound.isPlaying) {         
    [radiosound pause]; 
} else {                
     [radiosound play]; 
}

My app crashes, because AVPlayer doesn´t recognize "isPlaying".

Any tips?

like image 692
Ben Avatar asked Sep 07 '11 19:09

Ben


1 Answers

AVPlayer doesn't have an isPlaying property. Use the rate property (0.0 means stopped, 1.0 playing).

if (radiosound.rate == 1.0) {         
    [radiosound pause]; 
} else {                
     [radiosound play]; 
}

You can look at the AVPlayer class reference here.

like image 117
gcamp Avatar answered Sep 26 '22 06:09

gcamp