user722566
user722566

Reputation: 203

Making a button play and pause background sound

I have errors with my code:

-(IBAction)pause {
    [theAudio pause];

    if [theAudio pause] {
    else {
        [theAudio play];
    }
}
}

I am very new to c and xcode and I am really not sure what to do. Please provide the right code in relation to this.

Upvotes: 0

Views: 669

Answers (2)

Gavin Miller
Gavin Miller

Reputation: 43865

The code you posted has some syntax errors, it should look like the following:

-(IBAction)pause {      
    if ([theAudio isPaused]) {
        [theAudio play];
    } else {
        [theAudio pause];
    }
}

I have no idea if your theAudio object has an isPaused method, basically in the if statement you should be checking whether the audio is playing or not, and use that to set the audio to play or pause.

Upvotes: 0

justin
justin

Reputation: 104708

i suggest you team up with user 722566, and work through problems together:

https://stackoverflow.com/questions/5838749/error-expected-before-token-and-expected-declaration-or-statement-at-end

Making a button play and pause background sound

error: expected expression before 'else'

it seems like you two have a lot of identical questions, at approximately the same time.

thanks

Upvotes: 2

Related Questions