简体   繁体   中英

AVPlayer change volume, vertical slider

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?

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];

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM