android+仿ios+音乐播放器,iOS简单的音乐播放器(仿QQ音乐)

AVPlayer实现基本的播放,暂停,上一首,下一首,调节音量,调节进度等,正在学习的新人可以看下,有什么不足可以互相学习,谢谢支持

3bf68e41a22b?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

qq音乐.gif

这个是我写的一个简单的低仿QQ音乐, 如果你也喜欢听音乐的话, 快来自己制作一个吧!

下面我们来实现, 首先我们用单例写的音乐管理器, 我把它命名为MusicManager:

. h

//

// MusicManager.h

// 22-QQ音乐MV

//

// Created by dllo on 16/8/19.

// Copyright © 2016年 高雅馨. All rights reserved.

//

#import

#import

@interface MusicManager : NSObject

@property (nonatomic, strong) NSMutableArray *musicArray;

@property (nonatomic, assign) NSInteger index;

@property (nonatomic, assign) BOOL isPlay;

@property (nonatomic, strong) AVPlayer *player;

// 分享信息

+ (instancetype)shareInfo;

// 播放和暂停

- (void)playAndPause;

// 上一首

- (void)playPrevious;

// 下一首

- (void)playNext;

- (void)replaceItemWithUrlString:(NSString *)urlString;

// 调节音量

- (void)playerVolumeWithVolumeFloat:(CGFloat)volumeFloat;

// 播放进度条

- (void)playerProgressWithProgressFloat:(CGFloat)progressFloat;

@end

. m

//

// MusicManager.m

// 22-QQ音乐MV

//

// Created by dllo on 16/8/19.

// Copyright © 2016年 高雅馨. All rights reserved.

//

#import "MusicManager.h"

static MusicManager *_musicManager = nil;

@implementation MusicManager

+ (instancetype)shareInfo

{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

_musicManager = [[MusicManager alloc] init];

});

return _musicManager;

}

- (instancetype)init

{

if (self = [super init]) {

_player = [[AVPlayer alloc] init];

}

return self;

}

// 播放

- (void)playerPlay

{

[_player play];

_isPlay = YES;

}

- (void)playerPause

{

[_player pause];

_isPlay = NO;

}

- (void)playAndPause

{

if (self.isPlay) {

[self playerPause];

}else{

[self playerPlay];

}

}

- (void)playPrevious

{

if (self.index == 0) {

self.index = self.musicArray.count - 1;

}else{

self.index--;

}

}

- (void)playNext

{

if (self.index == self.musicArray.count - 1) {

self.index = 0;

}else{

self.index++;

}

}

- (void)playerVolumeWithVolumeFloat:(CGFloat)volumeFloat

{

self.player.volume = volumeFloat;

}

- (void)playerProgressWithProgressFloat:(CGFloat)progressFloat

{

[self.player seekToTime:CMTimeMakeWithSeconds(progressFloat, 1) completionHandler:^(BOOL finished) {

[self playerPlay];

}];

}

- (void)replaceItemWithUrlString:(NSString *)urlString

{

AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:urlString]];

[self.player replaceCurrentItemWithPlayerItem:item];

[self playerPlay];

}

@end

这里呢, 类已经封装好, 拿过去就可以用哈✌️

在VC里, 我是在API里抓的接口, 用起来很方便的, 推荐给大家这个网址:https://www.showapi.com/api/apiList?search=qq

写到这里也就差不多了, 下次会补充随机模式的. 相信大家在调用时会很容易呢, 页面也可以自己设计一下, (__) 嘻嘻……, 来实现吧, 很简单吼!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值