English 中文(简体)
AVAudio B. 行为者的拖延 景象
原标题:AVAudioPlayer delaying setImage from happening

申斥: 我对“我们的方案”相对来说是一个新问题,在我走到一边的时候,我正试图教授自己的基础......这样就是:-


I m building an app that plays a series of .mp3 files strung together using AVAudioplayer. So far, that part is working good. IBActions, and IBOutlets hooked up. Click the button, and the audio plays.

My problem is this: My play button has been added directly to the main.storyboard, set and custom with it s initial state defined in Interface Builder. When I click the play, I want to change the image of the button to indicate that it s playing. However, as soon as the audio starts, it almost seems like the view is... paused, or something. The button image stays the same, until the audio done playing. Only then, will the button image update itself -- hardly useful.

我也只是试图确定另一个随机的UIImageView的形象,该意见并不附属于这个特定纽州。 经验丰富。 一旦我发表我的演剧“阿雷”方法的话, but子就立即工作。


    -(IBAction)start_playing:(UIButton*)pressed_button {
    [_btn_start setImage:[UIImage imageNamed:@"btn_on-active"] forState:UIControlStateNormal];

    [self playAudioArray];
    }

我希望我已经离开了足够的时间来继续......。 任何想法/评论/建议?

Thanks a million - Drew

#

<>Update:

我发现,在我的音响上台时,对意见的更新就会中断。 这部法典规定罚款......


    if (audioPlayer.playing == YES) {

[audioPlayer pause];
[sender setImage:[UIImage imageNamed:@"btn_on.png"] forState:UIControlStateNormal];
[_btn_stop setImage:[UIImage imageNamed:@"btn_off.png"] forState:UIControlStateNormal];

} else {

NSString *path = [[NSBundle mainBundle] pathForResource:@"audio_file1" ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
audioPlayer.volume = 1.0;
audioPlayer.numberOfLoops = 0;
[audioPlayer setMeteringEnabled: YES];
[audioPlayer play];


//changes the image when the button is pressed
[sender setImage:[UIImage imageNamed:@"btn_on.png"] forState:UIControlStateNormal];
[_btn_stop setImage:[UIImage imageNamed:@"btn_off.png"] forState:UIControlStateNormal];

}

但该法典的编号如下。


    } else {

//changes the image when the button is pressed
[sender setImage:[UIImage imageNamed:@"btn_on.png"] forState:UIControlStateNormal];
[_btn_stop setImage:[UIImage imageNamed:@"btn_off.png"] forState:UIControlStateNormal];

NSArray  *theSoundArray = [NSArray arrayWithObjects:@"audio1",@"audio2",@"audio3",nil];

for (int i = 0; i < totalSoundsInQueue;) {

NSString *sound = [theSoundArray objectAtIndex:i];

// Wait until the audio player is not playing anything
while(![audioPlayer isPlaying]){

NSString *path = [[NSBundle mainBundle] pathForResource:@"mom" ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
audioPlayer.volume = 1.0;
audioPlayer.numberOfLoops = 0;
[audioPlayer setMeteringEnabled: YES];
[audioPlayer play];

i++;

}        

}

}

听音响亮,穿透我所有的音响,不发生错误。 我的纽伦州只有把 lo子固定下来。 我用多种不同类型的住宿方法尝试了这一问题。 对于每一个国家而言,尽管......我每次开始通过声音的剪辑,都发挥了巨大作用,但显示显示的焦点却松散。

Which reminds me. Once I m in the loop, my "Stop" button looses it s a clickable (tappable) nature. Until the loop has finished running. If I m not in a loop, the stop button works fine, no problems.

如果我在这里做一整新的错误的话,会问大家什么?

最佳回答

页: 1 代表AVAudioPlayer, 而不是连续经营。 录音机一旦投入使用,将发送<条码>-(避免)音频PlayerDidReachEnd;(你必须执行)。 然后,你可以在执行工作的问讯中打下一个音频文件。 你真的希望作为代表站立起来。 AVAudio 运动员将发出你的委托信息,要求中断(如发出电话)和编码错误。 你们希望以宽松的方式处理这些事件。

I think the reason the audio is playing fine is that is has a higher priority and runs on a separate thread. The reason the UI becomes un-responsive is even though animations/UI changes occur on a separate thread, they re initiated from the main thread. But all UI changes are queued to the end of a run-loop (so optimizations can be made). However, that run loop never ends because your for loop never ends until all the audio files are played. The audio files can be played in order because they re initiated in that for loop and run on a separate thread. Makes sense? In general, you really don t want to tie up the main thread.

问题回答

暂无回答




相关问题
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, ...

热门标签