UISlider not updating

uislider not moving
uislider value changed programmatically
uislider step increment
uislider thumb size
custom uislider swift
uislider not smooth
uislider example
uislider events

I am trying to code a music player for an assignment and I am stuck with trying to get the slider to update as the song is playing. I have been able to make it so that if the user were to slide the slider the song will rewind/fast-forward to that part of the song. Does anyone know why the slider doesn't continuously update as the song is playing?

Here is the .h file

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface AS3MPViewController : UIViewController <MPMediaPickerControllerDelegate>{
    IBOutlet UIButton *playButton;
    IBOutlet UIButton *stopButton;
    IBOutlet UIButton *pauseButton;
    IBOutlet UISlider *volumeSlider;
    AVAudioPlayer *musicPlayer;
    IBOutlet UIButton *pickSongButton;
    IBOutlet UISlider *timeSlider;
    NSTimer *timer;
}

@property (nonatomic, retain) UIButton *playButton;
@property (nonatomic, retain) UIButton *stopButton;
@property (nonatomic, retain) UIButton *pauseButton;
@property (nonatomic, retain) UISlider *volumeSlider;
@property (nonatomic, retain) AVAudioPlayer *musicPlayer;
@property (nonatomic, retain) UIButton *pickSongButton;
@property (nonatomic, retain) UISlider *timeSlider;
@property (nonatomic, retain) NSTimer *timer;

- (IBAction) play;
- (IBAction) stop;
- (IBAction) pause;
- (IBAction) changeVolume: (UISlider *)sender;
- (IBAction) chooseSong: (UIButton *)sender;
- (IBAction) changeTime: (UISlider *)sender;
- (void)setTimeSliderOptions;

@end

Here is the .m file

#import "AS3MPViewController.h"

@interface AS3MPViewController ()

@end

@implementation AS3MPViewController

@synthesize playButton = _playButton;
@synthesize stopButton = _stopButton;
@synthesize pauseButton = _pauseButton;
@synthesize musicPlayer = _musicPlayer;
@synthesize volumeSlider = _volumeSlider;
@synthesize pickSongButton = _pickSongButton;
@synthesize timeSlider = _timeSlider;
@synthesize timer;

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"animals001"     ofType:@"mp3"];

    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

    self.musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

    [self.musicPlayer prepareToPlay];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction) play {
    [self.musicPlayer play];

}

- (IBAction) stop {
    [self.musicPlayer stop];
    self.musicPlayer.currentTime = 0;
}

- (IBAction) pause {
    [self.musicPlayer pause];
}

- (IBAction) changeVolume: (UISlider *)sender {
    self.musicPlayer.volume = [sender value];
}

- (IBAction)chooseSong:(UIButton *)sender {
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];

    [mediaPicker setDelegate:self];
    [mediaPicker setAllowsPickingMultipleItems:NO];

    mediaPicker.prompt = NSLocalizedString(@"Add Some Songs To Play", "Prompt In Media Item Picker");

    [self presentModalViewController: mediaPicker animated:YES];
}

- (void) mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
[self dismissModalViewControllerAnimated:YES];
}

- (void) mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:    (MPMediaItemCollection *)mediaItemCollection {

    MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];
    NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

    //AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
    //AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];

    self.timeSlider.maximumValue = [self.musicPlayer duration];

    self.musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

    [self.musicPlayer play];

    timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(songCurrentTime) userInfo:nil repeats:YES];

    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)changeTime: (UISlider *)sender {
    self.musicPlayer.currentTime = self.musicPlayer.duration * sender.value;
}

- (void)songCurrentTime {
    timeSlider.value = (self.musicPlayer.currentTime / self.musicPlayer.duration);
}
@end

check in the connections that you are connected the IBAction method with slider with ValueChanged EX:

- (IBAction)changeTime: (UISlider *)sender {

check whether this method is connected with ValueChanged while IB connection

UISlider not updating current value in Swift, You can do it as you have using some tricks, first of all you need to set the target for the UISlider as some as suggested, the other point is get� Options that can not be updated will be ignored without errors. The value null can be used to unset a previously set value. The 'update' event fires after updating the slider. By default, the sliders values remain unchanged. To update the slider values, newOptions may also contain a start property that matches the signature of the .set() method.

I think your problem is that you are updating the value of the slider from a thread other than the main one. Try modifying the songCurrentTime method so that it calls another one on the main thread that updates the value of the slider.

- (void)songCurrentTime {
[self performSelectorOnMainThread:@selector(songCurrentTimeMain) withObject:nil waitUntilDone:YES];
}

- (void)songCurrentTimeMain {
timeSlider.value = (self.musicPlayer.currentTime / self.musicPlayer.duration);
}

Of course to get correct results make sure the minimum value of the slider is 0 and the maximum is 1.

Best Regards

UISlider, As you move the thumb of a slider, it passes its updated value to any actions attached to it. Use either a custom tint color or a custom image, but not both. Objective-C. Declare a slider property in the ViewController.h or in the interface of ViewController.m. @property (strong, nonatomic)UISlider *slider; //Define frame of slider and add to view CGRect frame = CGRectMake(0.0, 100.0, 320.0, 10.0); UISlider *slider = [[UISlider alloc] initWithFrame:frame]; [slider addTarget:self action:@selector(sliderAction:) forControlEvents

I've done something similar within this tutorial and the way I added a slider was the same as you did except for the fact that I used

musicPlayer.currentPlaybackTime

as a value to assign to the slider.

It may be that the result of (self.musicPlayer.currentTime / self.musicPlayer.duration) is an inaccurate assignment to your slider value.

UISlider, UISlider - beginTracking behaviour changed on iOS 12. Hi folks, The API diff shows no change at documentation level - I am looking forward to understand what changed here. Any help Any update on how to fix this issue ? Because i am� UISlider customization issue in iOS6 I have a custom UISlider but in iOS 6 there is a problem with the setMinimumTrackImage which as can be seen gets resized instead of clipped as it happened with iOS 5 and 4.

When you set your slider value, the value is always less than or equal to 1 because self.musicPlayer.currentTime is always less than or equal to self.musicPlayer.duration. Instead, try this

timeSlider.value = self.musicPlayer.currentTime;

UISlider Tutorial and Example (Updated for 2018), Actual outcome: The slider handle does not move. It stays to the left. They all used to work, and they all still work on Android. I note, that the "value� Major tick mark locations, specified as a vector of numeric values or an empty vector. If you do not want to show major tick marks, specify this property as an empty vector. Tick locations that are outside the range of the Limits property do not display. MATLAB removes duplicate tick values.

timeSlider and self.timeSlider are not the same thing. Most of the iVars that you have declared are unnecessary (and misleading) because you synthesize your properties using the underscore form of the property name. For example, you have a timeSlider property that's backed by a _timeSlider iVar, and a timeSlider iVar that's a different thing entirely.

Use self.timeSlider.value = ....

[TIMOB-25361] iOS: Ti.UI.Slider.setValue not updating the slider , So currently I have an options menu that updates the volume when the slider is changed. I am able to save the volume in a PlayerPrefs and it� I want to create a UISlider that when a user selects a tableview row. It updates the min & max value moves the slider to a value set by a variable. The slider is in a different Viewcontroller then the tableview. I am passing the values to the slider using a struct (Posted below). At this point, I ca

UI Slider does not update when value is loaded, the app, but you have no idea how to use it because it's your first time using it? How to personalize and use UISlider in Swift It's working! When I change my dropdown when it reaches ELSE condition textbox(ng-model="_ManualQty") is not updating please help me where im doing mistake. Source: New feed Source Url Please help me why my ng-model is not Updating during ng-change

How to personalize and use UISlider in Swift, The default stylesheet also sets a not-allowed cursor. The slider below is disabled when the checkbox is checked, and re-enabled when it is unchecked. var slider = document.getElementById('slider'); noUiSlider.create(slider, /* { options } */); // Set one handled slider slider.noUiSlider.set(10); slider.noUiSlider.set([150]); // Set the upper handle on a slider with two handles, // don't change the lower one slider.noUiSlider.set([null, 14]); // On a slider with three handles, // set the third to 12 (the handleNumber is 0-indexed) // Then

noUiSlider, sld = uislider creates a slider in a new figure window and returns the Slider object . The Value property of the Slider object is not updated until the user releases� @ IBAction func sliderValueChanged (sender: UISlider) {var currentValue = Int (sender. value) println ("Slider changing to \(currentValue) ?" ) sliderVal . text = "\(currentValue) Km" } I can see in the log the sliderValueChanged funciton is being called and the log is printing the value but the label's text is not updating.

Comments
  • As I read it, the docs seem to say that the player updates its own currentTime as it plays. No?
  • You're right, my mistake. I think I found the issue and edited my answer.
  • Thank you for the suggestions but I've tried that without any luck. I've tried to set the value to 0 and the maximumValue to the length of the song and then changed the update function as you posted but it still doesn't update for some reason.