Giter Club home page Giter Club logo

volume's Introduction

Volume

改变手机的媒体音量, 把文字转换为声音

OC版本代码

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
//    musicPlayer.volume =
    
    [[MPMusicPlayerController applicationMusicPlayer] setVolume: 0.9];
    [self.view addSubview:({
        UIButton * addVolumeButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 600, 50, 50)];
//        addVolumeButton.center = self.view.center;
        addVolumeButton.backgroundColor = [UIColor blueColor];
        addVolumeButton.titleLabel.text = @"addVolumeButton";
        [addVolumeButton addTarget:self action:@selector(addVolume) forControlEvents:UIControlEventTouchUpInside];
        addVolumeButton;
    })];
    MPVolumeView * view = [MPVolumeView new];
    view.frame = CGRectMake(100, 100, 300, 400);
     [self.view addSubview:view];
    
    
}


- (void)addVolume{
//    [[MPMusicPlayerController applicationMusicPlayer] setVolume: 1];
    [self setVolume:1];
}

- (void)setVolume: (float)value
{
    MPVolumeView *volumeView = [[MPVolumeView alloc] init];
    UISlider* volumeViewSlider = nil;
    for (UIView *view in [volumeView subviews]){
        if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
            volumeViewSlider = (UISlider*)view;
            break;
        }
    }
    volumeView.showsVolumeSlider = NO;
    
    // retrieve system volume
    //float systemVolume = volumeViewSlider.value;
    
    // change system volume, the value is between 0.0f and 1.0f
    [volumeViewSlider setValue:value animated:NO];
    
    // send UI control event to make the change effect right now.
    [volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
    
    [volumeView sizeToFit];
}

volume's People

Contributors

smallwolfios avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.