English 中文(简体)
管道和管道
原标题:Starting & Stopping a sound (Code provided) iOS

我有一个单一的声音,通过我的服务器在网上演出。 然而,它通过我的服务器成功运行,但音响似乎已经停止。 我曾试图将其编成法典,但我没有uck。 帮助

- (IBAction)oneSound:(id)sender; {
    if (ButtonAlReadyClicked == 1) 
    {
        ButtonAlReadyClicked = 2;

        [sender setBackgroundImage:[UIImage imageNamed:@"m2.png"] forState:UIControlStateNormal];

    }
    else if (ButtonAlReadyClicked == 2) 
    {
        ButtonAlReadyClicked = 1;

        [sender setBackgroundImage:[UIImage imageNamed:@"m1.png"] forState:UIControlStateNormal];

    }  
    if (player && player.playing) {
        [player stop];
        [player release];
        player = nil;
        return;
    }    

    AVPlayer *player = [[AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.mysite.com/hi.mp3"]] retain];

    [player play];

}

我发现的错误:使用未申报的识别器[3]

问题回答

The if (player … line always returns false because you have player as a local variable, not an instance ivar. Add a player ivar to your .h file, then save the one you init to it, not to a local player.

你们需要在被点击的纽芬兰语中宣布一个变数。 之所以出现错误,是因为在你尝试和获取变数后,参与者变数被宣布为变数,并占用财产。

- (IBAction)oneSound:(id)sender {
    if (player == nil) {
        player = [[AVPlayer playerWithURL:[NSURL URLWithString:@"http://www.mysite.com/hi.mp3"]] retain];
        [player play];
        ButtonAlReadyClicked = 1;
        [self oneSound:sender];
        return;
    }
    if (ButtonAlReadyClicked == 1) {
        ButtonAlReadyClicked = 2;
        [sender setBackgroundImage:[UIImage imageNamed:@"m2.png"] forState:UIControlStateNormal];
    }
    else if (ButtonAlReadyClicked == 2) 
    {
        ButtonAlReadyClicked = 1;
        [sender setBackgroundImage:[UIImage imageNamed:@"m1.png"] forState:UIControlStateNormal];
    }  
    if (player && player.playing) {
        [player stop];
        [player release];
        player = nil;
        return;
    }    

}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签