zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    SQL Server执行计划的理解
    SQL Server Profiler工具
    利用SQL Profiler处理开销较大的查询
    查询开销
    详解索引连接类型
    详解执行计划
    数据库引擎调整顾问
    six.moves的用法
    ※数据结构※→☆非线性结构(tree)☆============二叉树 顺序存储结构(tree binary sequence)(十九)
    C++ 线程的创建,挂起,唤醒,终止
  • 原文地址:https://www.cnblogs.com/ylg-----/p/4753018.html
Copyright © 2011-2022 走看看