绘制播放音乐时的音波图形的View
绘制播放音乐时的音波图形的View
这个效果类似于这个哦:
效果如下:
源码:
MusicView.h 与 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; // 进程百分比,取值为[0,1]
@property (nonatomic, assign) CGFloat timeInterval; // 时间间隔 @end
//
// MusicView.m
// Music
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "MusicView.h" @interface MusicView () @property (nonatomic, assign) CGRect baseRect; // 备份原始的frame值 @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 <= ) {
_progress = ;
} else if (progress >= ) {
_progress = ;
} else {
_progress = progress;
} [UIView animateWithDuration:(_timeInterval > ? _timeInterval : 0.99) animations:^{
CGRect rect = _baseRect;
rect.size.height *= _progress;
self.frame = rect;
}];
}
- (CGFloat)progress
{
return _progress;
} @end
使用时的情形:
//
// 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]; // 线条1
_musicViewLine1 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_musicViewLine1.backgroundColor = [UIColor redColor];
_musicViewLine1.timeInterval = 0.5f;
[self.view addSubview:_musicViewLine1]; // 线条2
_musicViewLine2 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_musicViewLine2.backgroundColor = [UIColor redColor];
_musicViewLine2.timeInterval = 0.5f;
[self.view addSubview:_musicViewLine2]; // 线条3
_musicViewLine3 = [[MusicView alloc] initWithFrame:CGRectMake(, , , )];
_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()%/.f;
_musicViewLine2.progress = arc4random()%/.f;
_musicViewLine3.progress = arc4random()%/.f;
} @end
以下是核心代码:
绘制播放音乐时的音波图形的View的更多相关文章
- Android播放音乐时跳动的屏谱demo
Android实现播放音频时的跳动频谱,并实现可以调节的均衡器. Main.java package com.wjq.audiofx; import android.app.Activity; imp ...
- 关于Windows 8使用WMP播放音乐时WUDFHost跑CPU和硬盘的问题解决
Windows 8使用Windows Media Player播放音乐的时候.事实上有一个这种情况,WMP和某个什么名字看起来非常屌的进程跑CPU非常高,这个跑非常高视你插入的SD卡内的文件数或者移动 ...
- Linux版网易云音乐播放音乐时无限显示“网络错误”的解决办法
安装 gstreamer0.10-plugins-good debian类系统: -plugins-good
- 【分享】4412开发板ubuntu 12.0.4播放音乐没有声音解决方法
转自迅为论坛:http://bbs.topeetboard.com 准备工作 1.下载 vim 在命令行上输入 apt-get install vim 下载 vim 2.输入 vim /etc/hos ...
- android 播放音乐-进度条
今天学渣研究了一下使用MediaPlayer播放音乐时加入进度条,进度条如今用的是android自带的seekbar,后期会跟换UI的,在之前可以播放音乐的基础上,如今加入的主要功能有两个: 1实时显 ...
- MUI---IOS切换到后台继续播放音乐
应用切换到后台继续音乐播放HBuilder默认生成的应用在iOS是不支持后台音乐播放的,当应用切换到后台时音乐将暂停播放,下次切换到前台继续播放.如果要支持应用切换到后台后继续播放音乐功能需要进行额外 ...
- Inno调用dll --- 实现背景播放音乐
Inno 播放音乐可以调用系统api函数mciSendString来实现,而mciSendString函数存在C:\Windows\System32\winmm.dll中,因此最终只要成功从该dll文 ...
- iOS开发系列--扩展--播放音乐库中的音乐
众所周知音乐是iOS的重要组成播放,无论是iPod.iTouch.iPhone还是iPad都可以在iTunes购买音乐或添加本地音乐到音乐 库中同步到你的iOS设备.在MediaPlayer.fram ...
- iPhone播放音乐
来源:http://blog.csdn.net/htttw/article/details/7842295 iPhone播放音乐 今天我们简要介绍如何在iPhone中播放音乐: 强烈建议你参考官方文档 ...
随机推荐
- 一个数字键盘引发的血案——移动端H5输入框、光标、数字键盘全假套件实现
https://juejin.im/post/5a44c5eef265da432d2868f6 为啥要写假键盘? 还是输入框.光标全假的假键盘? 手机自带的不用非得写个假的,吃饱没事干吧? 装逼?炫技 ...
- Struts中Validate()和validateXxx的使用
Struts中Validate()和validateXxx的使用 学习struts2之后,你会发现validate在之前是没有的!它是怎么实现的呢? validate和validateXxxx都是拦截 ...
- 关于sql通配符检索问题-【.NET】
确定给定的字符串是否与指定的模式匹配.模式可以包含常规字符和通配符字符.模式匹配过程中,常规字符必须与字符串中指定的字符完全匹配.然而,可使用字符串的任意片段匹配通配符.与使用 = 和 != 字符串比 ...
- XmlReader在序列化中的使用
和XmlDocument最大的不同——XmlReader逐行读取.单独很少使用,一般配合序列化(反序列化)使用,以下给出具体例子: namespace ConsoleApplication1 { pu ...
- C#中要使ListBox使用AddRange()时,能够触发SelectedValueChanged事件
1. 要触发 SelectedValueChanged事件,必须要当ListBox所选中的值发生改变 基本思路是: 当AddRange()后,就马上指定ListBox的SelectedIndex,这样 ...
- IE浏览器报Promise未定义
用vue-cli做的项目,用了promise,结果IE下报promise未定义,甚至在比较老的andriod手机浏览器上会显示空白页面,解决方案如下: 首先安装:babel-polyfill npm ...
- no jpeg in java.library.path;java.lang.NoClassDefFoundError: Could not initialize class sun.awt.image.codec.JPEGImageEncoderImpl
no jpeg in java.library.path;java.lang.NoClassDefFoundError: Could not initialize class sun.awt.imag ...
- 深入理解JavaScript系列(41):设计模式之模板方法
介绍 模板方法(TemplateMethod)定义了一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 模板方法是一种代码复用的 ...
- centos下mongodb安装
安装说明: 系统环境:Centos-6.5 安装软件:mongodb-linux-x86_64-2.4.9.tgz 下载地址:http://www.mongodb.org/downloads 上传位置 ...
- request方法总结
1.获得指定的头 String header = response.getHeader("user-agent"); 2.获得所有头的名称 Enumeration<Stri ...