View of audio and wave graphics when playing music

Source: Internet
Author: User

View of audio and wave graphics when playing music

This effect is similar to this:

The effect is as follows:

Source code:

Musicview. h and musicview. m

//// Musicview. h // music // copyright (c) 2014 y. x. all rights reserved. // # import <uikit/uikit. h> @ interface musicview: uiview @ property (nonatomic, assign) cgfloat progress; // process percentage. Value: [0, 1] @ property (nonatomic, assign) cgfloat timeinterval; // time interval @ end
//// Musicview. M // music // copyright (c) 2014 y. x. all rights reserved. // # import "musicview. H "@ interface musicview () @ property (nonatomic, assign) cgrect baserect; // back up the original frame value @ end @ implementation musicview-(ID) initwithframe :( cgrect) frame {self = [Super initwithframe: frame]; If (Self) {_ baserect = frame;} return self ;}@ synthesize progress = _ progress;-(void) setprogress :( cgfloat) Progress {if (Progress <= 0) {_ progress = 0;} else if (Progress >=1) {_ progress = 1 ;}else {_ progress = progress ;} [uiview animatewithduration :( _ timeinterval> 0? _ Timeinterval: 0.99) animations: ^ {cgrect rect = _ baserect; rect. size. height * = _ progress; self. frame = rect ;}] ;}- (cgfloat) SS {return _ progress ;}@ end

Usage:

//// Rootviewcontroller. M // music // copyright (c) 2014 y. x. all rights reserved. // # import "rootviewcontroller. H "# import" musicview. H "@ interface rootviewcontroller () @ property (nonatomic, strong) nstimer * timer; @ property (nonatomic, strong) musicview * musicviewline1; @ property (nonatomic, strong) musicview * musicviewline2; @ property (nonatomic, strong) musicview * musicviewline3; @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; // line 1 _ musicviewline1 = [[musicview alloc] initwithframe: cgrectmake (100,100, 4, 20)]; _ blank = [uicolor redcolor]; _ musicviewline1.timeinterval = 0.5f; [self. view addsubview: _ musicviewline1]; // line 2 _ musicviewline2 = [[musicview alloc] initwithframe: cgrectmake (108,100, 4, 20)]; _ musicviewline2.backgroundcolor = [uicolor redcolor]; _ musicviewline2.timeinterval = 0.5f; [self. view addsubview: _ musicviewline2]; // line 3 _ musicviewline3 = [[musicview alloc] initwithframe: cgrectmake (116,100, 4, 20)]; _ musicviewline3.backgroundcolor = [uicolor redcolor]; _ musicviewline3.timeinterval = 0.5f; [self. view addsubview: _ musicviewline3]; _ timer = [nstimer scheduledtimerwithtimeinterval: 0.5f target: Self selector: @ selector (timerevent) userinfo: Nil repeats: Yes];}-(void) timerevent {_ musicviewline1.progress = arc4random () % 100/100. f; _ musicviewline2.progress = arc4random () % 100/100. f; _ musicviewline3.progress = arc4random () % 100/100. f ;}@ end

The following is the core code:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.