English 中文(简体)
音乐进步节
原标题:Music progress bar

目前,我正在撰写一部基于 Apple果的乐器,我想给它增加一条进步。

我怎么能够取得进展,以显示在我所期望的“静默”中正在玩的音乐的进展?

问题回答

This is how I accomplised this In the header file I declared these variables.

www.un.org/Depts/DGACM/index_spanish.htm

<编码> UISlider *timeSlider;

<代码>BOOL用户IsScrubbing;

- (IBAction)handleScrubber TouchDown (id)sender;

- (IBAction)handleScrubberTouchUp:id)sender;

- (IBAction)handleScrub(id)sender;

In the main file now under the viewDidLoad method, I ran an NSTimer currentTimeUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateCurrentiPodItemTime) userInfo:NULL repeats:YES];

<代码>用户代码Scrubbing = NO;

之后,这是一个更新所有事项。

- (void)updateCurrentiPodItemTime {
    MPMediaItem *nowPlayingItem = [self.musicPlayer nowPlayingItem];

if (nowPlayingItem == nil) {
    self.minLabel.text = @"00:00";

} else {
    NSNumber *duration = [nowPlayingItem valueForProperty:MPMediaItemPropertyPlaybackDuration];
    double currentTime = self.musicPlayer.currentPlaybackTime;
    self.minLabel.text = [NSString stringWithFormat: @"%02d:%02d", (int) currentTime / 60, (int) currentTime % 60];     
    self.maxLabel.text = [NSString stringWithFormat: @"%02d:%02d", [duration intValue] / 60, [duration intValue] % 60];

    if (!userIsScrubbing)
        self.timeSlider.value = (float) currentTime;
    }
}

- (IBAction)handleScrubberTouchDown:(id)sender {
     userIsScrubbing = YES;
}

- (IBAction)handleScrubberTouchUp:(id)sender {
    userIsScrubbing = NO;
}

- (IBAction)handleScrub:(id)sender {
    self.musicPlayer.currentPlaybackTime = timeSlider.value;
}

Add a timer to fire every second (1.0) and get it to call an method to update the progress bar like the one below:

- (void) updateProgressBar:(NSTimer *) timer {
    if (currentPlaybackTime != lengthOfSong) {
        [self.progressBar setValue:self.musicPlayer.currentTime];
    }
    else {
        [timer invalidate], timer = nil;
        [self.progressBar setValue:lengthOfSong];
    }
}

Add a UIProgressView to your view and update it periodically.





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

热门标签