I have several UIButtons that control the iPhone's music player.
I would like to have the music player seek backwards if the previous button is touched and held, but skip to the previous item if the button is single-tapped.
Currently, I am able to skip to the previous item with a tap, but touching and holding will seek backwards AND skip to the previous item once the button is touched up.
Here is the code I am currently using:
- (void)previousButtonTouchedDown {
[self performSelector:@selector(seekBackwards) withObject:nil afterDelay:1];
}
- (void)previousButtonTouchedUpInside {
MPMusicPlaybackState playbackState = self.iPodPlayer.playbackState;
if (playbackState == MPMusicPlaybackStateSeekingBackward) {
[self.iPodPlayer endSeeking];
} else {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(seekBackwards) object:nil];
[self.iPodPlayer skipToPreviousItem];
}
}
- (void)seekBackwards {
[self.iPodPlayer beginSeekingBackward];
}
How can I seek forward, but not skip to the previous item, if the button is touched, held, then touched up?
Thanks.
I haven't tested this, and I don't know if it's the best solution.
How does that sound?
Huh.
After running my app on a device with OS 3.1.2 (using the same code from the original post), it appears that the issue is fixed. The same code that seeks AND skips on a 3.0 device ONLY seeks on a 3.1.2 device.
So it seems that on 3.0, the player's playback state on UIControlEventTouchedUp is equal to playing, not skipping. On 3.1.2, it's the opposite.
Does anyone know of a solution that doesn't involve checking the player's playback state?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.