iso 开发学习--简易音乐播放器(基于iPhone4s屏幕尺寸)
三个按钮 一个进度条
贴图(软件中部分图片,来自网络,如果侵犯了您的权益,请联系我,会立刻撤下)

核心代码
//
// ViewController.m
// 08-10-MusicPlayer
//
// Created by Ibokan on 15/8/10.
// Copyright (c) 2015年 Crazy凡. All rights reserved.
// #import "ViewController.h"
#import <AVFoundation/AVFoundation.h> @interface ViewController ()
@property (nonatomic,strong)UIImageView * imageview;
@property (nonatomic,strong)UISlider *slider;
@property (nonatomic,strong)UIButton *buttonPlay;
@property (nonatomic,strong)UIButton *buttonPause;
@property (nonatomic,strong)UIButton *buttonStop;
@property (nonatomic,strong)AVAudioPlayer *player;
@property (nonatomic,strong)NSTimer *timer; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageview = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
[self.imageview setImage:[UIImage imageNamed:@"bgimg.jpg"]];
self.imageview.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.imageview.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.imageview];
//初始化背景 self.slider = [[UISlider alloc]initWithFrame:CGRectMake(, , , )];
self.slider.value = 0.0;
[self.view addSubview:self.slider];
[self.slider addTarget:self action:@selector(updateValue) forControlEvents:UIControlEventValueChanged]; self.buttonPlay = [[UIButton alloc]initWithFrame:CGRectMake(, ,, )];
[self.view addSubview:self.buttonPlay];
[self.buttonPlay setBackgroundImage:[UIImage imageNamed:@"starten.png"] forState:UIControlStateNormal];
[self.buttonPlay setBackgroundImage:[UIImage imageNamed:@"startun.png"] forState:UIControlStateDisabled];
//初始化并插入A self.buttonPause = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
[self.view addSubview:self.buttonPause];
self.buttonPause.enabled = false;
[self.buttonPause setBackgroundImage:[UIImage imageNamed:@"stopen.png"] forState:UIControlStateNormal];
[self.buttonPause setBackgroundImage:[UIImage imageNamed:@"stopun.png"] forState:UIControlStateDisabled];
//初始化并插入B
self.buttonStop = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
[self.view addSubview:self.buttonStop];
self.buttonStop.enabled = false;
[self.buttonStop setBackgroundImage:[UIImage imageNamed:@"pauseen.png"] forState:UIControlStateNormal];
[self.buttonStop setBackgroundImage:[UIImage imageNamed:@"pauseun.png"] forState:UIControlStateDisabled];
//初始化并插入C NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"tianyaguoke" ofType:@"mp3"];
//NSLog(@"%@",path);
NSURL * url = [NSURL fileURLWithPath: path];
self.player= [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[self.buttonPlay addTarget:self action:@selector(tapA) forControlEvents:UIControlEventTouchUpInside];
[self.buttonPause addTarget:self action:@selector(tabB) forControlEvents:UIControlEventTouchUpInside];
[self.buttonStop addTarget:self action:@selector(tabC) forControlEvents:UIControlEventTouchUpInside]; }
- (void)tapA
{
self.buttonPlay.enabled = false;
self.buttonPause.enabled = true;
self.buttonStop.enabled = true;
[self.player play];
self.timer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(timeadd) userInfo:nil repeats:YES];
}
- (void)tabB
{
self.buttonPlay.enabled = true;
self.buttonPause.enabled = false;
self.buttonStop.enabled = false;
[self.player stop];
self.player.currentTime = ;
}
- (void)tabC
{ self.buttonPlay.enabled = true;
self.buttonPause.enabled = true;
self.buttonStop.enabled = false;
[self.player pause];
}
- (void)timeadd
{
// double alltime = self.player.duration;
// double now = self.player.currentTime;
self.slider.value = self.player.currentTime/self.player.duration;
}
- (void)updateValue
{
self.player.currentTime = self.player.duration * self.slider.value;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
知识点总结:
1、[self.buttonPlay setBackgroundImage:[UIImage imageNamed:@"starten.png"] forState:UIControlStateNormal];
//为按钮添加图片
2、[self.slider addTarget:self action:@selector(updateValue) forControlEvents:UIControlEventValueChanged];
//slider(进度条)添加回调方法
3、self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeadd) userInfo:nil repeats:YES];
//NStimer的使用
4、NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"tianyaguoke" ofType:@"mp3"];
NSURL * url = [NSURL fileURLWithPath: path];
self.player= [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
//NSBundle、NSURL 为AVAudio 添加路径
5、self.imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.imageview setImage:[UIImage imageNamed:@"bgimg.jpg"]];
self.imageview.backgroundColor = [UIColor groupTableViewBackgroundColor];
//UIImageView 初始化
6、self.imageview.contentMode = UIViewContentModeScaleAspectFill;
self.imageview.contentMode = UIViewContentModeScaleAspectFit;
self.imageview.contentMode = UIViewContentModeScaleToFill;
//UIImageViewv 图片显示方式设定:比例充满 比例缩放 拉伸充满
7、self.player.currentTime;self.player.duration
//音乐播放器时间(当前播放的时间,时间总长)
点我下载源码 因为文件大小问题,文件中的音频被我删掉了,另附文件布局,我想大家可以看懂!

iso 开发学习--简易音乐播放器(基于iPhone4s屏幕尺寸)的更多相关文章
- ios开发学习- 简易音乐播放器2 (基于iPhone4s屏幕尺寸)-- 歌词解析--plist文件应用--imageNamed图片加载耗内存
声明:(部分图片来自网络,如果侵犯了您的权益请联系我,会尽快删除!) 又是音乐播放器,不过这次和上次不一样了,准确说这次更像播放器了,初学者不建议看这个,可以先看前面一个音乐播放器(1),当然 我没加 ...
- 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...
- 微信小程序(有始有终,全部代码)开发---跑步App+音乐播放器 Bug修复
开篇语 昨晚发了一篇: <简年15: 微信小程序(有始有终,全部代码)开发---跑步App+音乐播放器 > 然后上午起来吃完午饭之后,我就准备继续开工的,但是突然的,想要看B站.然后在一股 ...
- 记一次酷狗音乐API的获取,感兴趣的可以自己封装开发自己的音乐播放器
1.本教程仅供个人学习用,禁止用于任何的商业和非法用途,如涉及版权问题请联系笔者删除. 2.随笔系作者原创文档,转载请注明文档来源:http://www.cnblogs.com/apresunday/ ...
- ios开发:一个音乐播放器的设计与实现
github地址:https://github.com/wzpziyi1/MusicPlauer 这个Demo,关于歌曲播放的主要功能都实现了的.下一曲.上一曲,暂停,根据歌曲的播放进度动态滚动歌词, ...
- Android音乐播放器的设计与实现
目录 应用开发技术及开发平台介绍 应用需求分析 应用功能设计及其描述 应用UI展示 一.应用开发技术及平台介绍 ①开发技术: 本系统是采用面向对象的软件开发方法,基于Android studio开发平 ...
- 使用react native制作的一款网络音乐播放器
使用react native制作的一款网络音乐播放器 基于第三方库 react-native-video设计"react-native-video": "^1.0.0&q ...
- 基于Basys2开发板的简易电子琴和音乐播放器设计
背景:华中科技大学 电测综合实验 主要功能:Basys2开发板外接一个扬声器(或无源蜂鸣器也可)实现电子琴和音乐播放器的功能.其中由于开发板上只有4个按键,所以电子琴功能只做了4个音调,分别对应于4个 ...
- python 开发在线音乐播放器-简易版
在线音乐播放器,使用python的Tkinter库做了一个界面,感觉这个库使用起来还是挺方便的,音乐的数据来自网易云音乐的一个接口,通过urllib.urlopen模块打开网址,使用Json模块进行数 ...
随机推荐
- 还原virtual函数的本质-----C++
当你每次看到C++类中声明一个virtual函数,特别是看到了一个virtual的虚构函数.你知道它的意思吗?你肯定会毫不犹豫的回答:不就是多态么...在运行时确定具体的行为么...完全正确,但这里我 ...
- c++ 字符串流 sstream(常用于格式转换) 分类: C/C++ 2014-11-08 17:20 150人阅读 评论(0) 收藏
使用stringstream对象简化类型转换 C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性.类型安全和可扩展性.在本文中 ...
- VirtualBox 运行失败
运行 VirtualBox --help 安装 VirtualBox 后 运行 报错内核没加载问题 需要设置环境变量 内核加载的环境变量 export KERN_DIR=/usr/src/kernel ...
- SA密钥长度、明文长度和密文长度
本文介绍RSA加解密中必须考虑到的密钥长度.明文长度和密文长度问题,对第一次接触RSA的开发人员来说,RSA算是比较复杂的算法,RSA的复杂度是因为数学家把效率和安全也考虑进去的缘故. 本文先只谈密钥 ...
- svn 1.8.11 命令行提交新添加文件错误
由于公司的svn服务器版本不兼容最新的svn 1.8.11导致 提交代码报错 ➜ images svn ci arrowico.png -m"add images for png ico ...
- Java——(十)网络编程
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.Java的基本网络支持 Java为网络支持提供了java.net包,该包下的URL和URLC ...
- Store update, insert, or delete statement affected an unexpected number of rows ({0}).
问题描述 Store update, insert, or delete statement affected an unexpected number of rows ({0}). Entities ...
- Deep Learning 学习随记(八)CNN(Convolutional neural network)理解
前面Andrew Ng的讲义基本看完了.Andrew讲的真是通俗易懂,只是不过瘾啊,讲的太少了.趁着看完那章convolution and pooling, 自己又去翻了翻CNN的相关东西. 当时看讲 ...
- UIView下使用Animation控制动画
转载自:http://blog.csdn.net/xunyn/article/details/8128031 动画效果是IOS界面重要的特色之一,其中CAAnimation是所有动画对象的抽象父类,作 ...
- 使用IDEA,利用SpringMVC框架建立HelloWorld项目
无论是从头开始学习一门新的语言还是技术,我们的入门都是从HelloWorld开始,也许就是因为这样,我在学习Spring MVC的时候,就有一种偏执,一定要写出一个HelloWorld来.研究了好久, ...