• IOS-音乐播放器


    #import "ViewController.h"

    @interface ViewController ()<</span>AVAudioPlayerDelegate>

    @property(nonatomic,strong)UIProgressView * progressView;

    @property(nonatomic,strong)AVAudioPlayer * player;

    @property(nonatomic,strong)NSTimer * timer;

    -(void)timerprogress;

    @property(nonatomic,strong)UISlider * slider;

    -(void)tapslider;

    @end

    @implementation ViewController

    - (IBAction)Stop:(id)sender {

    [self.player stop];

    self.player.currentTime = 0;

    }

    - (IBAction)zanting:(id)sender {

    [self.player pause];

    }

    - (IBAction)Start:(id)sender {

    [self.player play];

    }

    - (void)viewDidLoad {

    [super viewDidLoad];

    self.progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(80, 400, 250, 2)];

    self.progressView.backgroundColor = [UIColor groupTableViewBackgroundColor];

    self.progressView.progress = 0;

    [self.view addSubview:self.progressView];

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

    NSURL * url = [NSURL fileURLWithPath:filePath];

    self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:urlerror:nil];

    self.player.volume = 0.5;

    self.player.numberOfLoops = -1;//循环播放

    //准备歌曲播放

    [self.player prepareToPlay];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1target:self selector:@selector(timerprogress) userInfo:nilrepeats:YES];

    self.slider = [[UISlider alloc]initWithFrame:CGRectMake(80, 450, 210, 2)];

    self.slider.maximumValue = 3;

    self.slider.minimumValue = 0;

    self.slider.value = 0.3;

    [self.slider addTarget:self action:@selector(tapslider)forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:self.slider];

    self.player.delegate = self;

    }

    -(void)timerprogress

    {

    self.progressView.progress = (self.player.currentTime /self.player.duration);

    }

    -(void)tapslider

    {

    self.player.volume = self.slider.value;

    }

    -(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag

    {

    [self.timer invalidate];

    }

    - (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    ActiveMQ学习第八篇:Consumer
    ActiveMQ学习第七篇:Messaage
    线性判别分析LDA
    逻辑回归
    那些年,曾踩过的Spark坑
    HBase表创建、删除、清空
    python的多线程
    python的多进程
    python实现读写txt文件
    python的封包和解包
  • 原文地址:https://www.cnblogs.com/ylg-----/p/4753018.html
Copyright © 2020-2023  润新知