0

Is there a way to change the volume on avplayer using a vertical slider, MPVolumeView is just horizontal and it doesn't seems to exist a way to do that.
I could have used a custom slider: on iOS7 we have the volume property to interact with, on iOS6 it seems that the only solution is the AudioMix Trick, but the last one seems to work only with "file" tracks not streaming content (I need to use them).
Has someone came up with an idea?

Community
  • 1
  • 1
Andrea
  • 26,120
  • 10
  • 85
  • 131
  • Maybe try doing a transform on MPVolumeView? – amergin Oct 06 '14 at 15:48
  • Using auto layout you are going to have a major issue – Andrea Oct 07 '14 at 07:05
  • Yeah, not sure how it'd work as I haven't tried it. If I get around to testing it I'll get back to you. Maybe sitting the MPVolumeView inside a non-rotated view which has all the autolayout stuff done on it. Either way it's going to be a botch. – amergin Oct 07 '14 at 07:18
  • 1
    If Autolayout is an issue, why not just create a container view that's the correct width, then add the `MPVolumeView` as a subview, and apply the transform? – ChrisH Oct 07 '14 at 16:43
  • @ChrisH it could work I will look into that, thanks+ – Andrea Oct 07 '14 at 17:22

2 Answers2

2

This worked for me (iPhone 5, iOS 8.3):

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(225, 270, 160, 30)];

CGAffineTransform sliderRotation = CGAffineTransformIdentity;
sliderRotation = CGAffineTransformRotate(sliderRotation,-(M_PI / 2));
volumeView.transform = sliderRotation;

[self.view addSubview:volumeView];
Frak
  • 832
  • 1
  • 11
  • 32
  • I had a placeholder view in the storyboard that I added the MPVolumeView as a subview of. I needed to ensure that the center of the MPVolumeView was the center of that view to get the rotation to be correct. – Gary Makin Dec 08 '15 at 03:55
1

This worked for me on IOS 8.4 subclassing MPVolumeView and placing an UIView in a XIB file with the position I wanted.

First subclass MPVolumeView.

@implementation UIPlayerVolume

- (void)awakeFromNib {
    [super awakeFromNib];

    CGRect originalFrame = self.frame;

    self.translatesAutoresizingMaskIntoConstraints = YES;

    CGAffineTransform sliderRotation = CGAffineTransformIdentity;
    sliderRotation = CGAffineTransformRotate(sliderRotation,-(M_PI / 2));
    self.transform = sliderRotation;

    self.frame = originalFrame;
}

@end
zevarito
  • 362
  • 4
  • 9