gpt4 book ai didi

ios - 如何在 ios 的歌曲加载时间中显示或隐藏事件指示器

转载 作者:行者123 更新时间:2023-12-01 16:35:39 25 4
gpt4 key购买 nike

我在 iOS 的 AVAudioplayer 工作。如果用户单击播放按钮,我将显示加载时间的事件指示器。我的问题是,当我单击播放按钮时,会显示加载时间事件指示器。在播放时间也显示事件指示器,这是我的问题。我需要在歌曲播放时间隐藏事件指示器

- (void)playOrPauseButtonPressed:(id)sender

{

[self.view addSubview:today_slokaText];

if (playing == NO)

{

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

[playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
forState:UIControlStateNormal];

[self.view addSubview:today_slokaText];

// Here Pause.png is a image showing Pause Buttomn

NSError *err = nil;

if (!audioPlayer)

{

[self loadSongAtIndex:selectedIndex];

playing = YES;
}

if (err)

{

NSLog(@"Error %ld,%@", (long)err.code, err.localizedDescription);
}

NSTimeInterval bufferDuration = 0.005;

[audioSession setPreferredIOBufferDuration:bufferDuration error:&err];

if (err)

{

NSLog(@"Error %ld, %@", (long)err.code, err.localizedDescription);
}

double sampleRate = 44100.0;

[audioSession setPreferredSampleRate:sampleRate error:&err];

if (err)

{

NSLog(@"Error %ld, %@", (long)err.code, err.localizedDescription);
}

[audioSession setActive:YES error:&err];

if (err)

{

NSLog(@"Error %ld,%@", (long)err.code, err.localizedDescription);
}

sampRate = audioSession.sampleRate;

bufferDuration = audioSession.IOBufferDuration;

NSLog(@"SampeRate:%0.0fHZI/OBufferDuration:%f", sampleRate, bufferDuration);

audioPlayer.numberOfLoops = 0;

[audioPlayer prepareToPlay];

[audioPlayer play];

audioPlayer.delegate = self;

if (!audioPlayer.playing)

{

[audioPlayer play];

activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

[self.view addSubview:self.activityIndicator];

self.activityIndicator.center = CGPointMake(
self.view.frame.size.width / 2, self.view.frame.size.height / 2);

[self.activityIndicator startAnimating];

[playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
forState:UIControlStateNormal];

[bg_Image addSubview:activityIndicator];

}

else if (audioPlayer.playing == YES)

[audioPlayer play];

[self.activityIndicator stopAnimating];

[playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
forState:UIControlStateNormal];

playing = YES;

}

else if (playing == YES)

{

[self.activityIndicator stopAnimating];

[bg_Image addSubview:activityIndicator];

[playButton setBackgroundImage:[UIImage imageNamed:@"play12.png"]
forState:UIControlStateNormal];

[self.view addSubview:today_slokaText];

[audioPlayer pause];

playing = NO;

timer = [NSTimer
scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateViewForPlayerState)
userInfo:nil
repeats:YES];

[self.view addSubview:today_slokaText];
}
}

最佳答案

为什么停止后将其添加为 subview ?
您可以将其 alpha 设置为 0.0 或从 superview 中删除:

[self.activityIndicator stopAnimating];
self.activityIndicator.alpha = 0.0;

关于ios - 如何在 ios 的歌曲加载时间中显示或隐藏事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28579779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com