Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit bfdcabe8
由
cgx
编写于
2022-06-19 22:05:39 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完成舒眠课程和助眠音乐息屏播放功能
1 个父辈
859a366c
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
154 行增加
和
18 行删除
DreamSleep/DreamSleep/Basement/Utils/DSConstUtil.h
DreamSleep/DreamSleep/Basement/Utils/DSConstUtil.m
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/CourseDetailController.m
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/MusicPlayerController.m
DreamSleep/DreamSleep/Resource/Assets.xcassets/.DS_Store
DreamSleep/DreamSleep/Basement/Utils/DSConstUtil.h
查看文件 @
bfdcabe
...
@@ -41,6 +41,10 @@ FOUNDATION_EXTERN NSString * const ExitCoaxSleep;
...
@@ -41,6 +41,10 @@ FOUNDATION_EXTERN NSString * const ExitCoaxSleep;
FOUNDATION_EXTERN
NSString
*
const
NeedUpdateAICoach
;
FOUNDATION_EXTERN
NSString
*
const
NeedUpdateAICoach
;
// 更新是否开启AI通知
// 更新是否开启AI通知
FOUNDATION_EXTERN
NSString
*
const
NeedUpdateStartAI
;
FOUNDATION_EXTERN
NSString
*
const
NeedUpdateStartAI
;
// 解锁音频成功通知
FOUNDATION_EXTERN
NSString
*
const
UnlockAudioSuccess
;
// 监听息屏播放页面点击播放、上一首、下一首通知
FOUNDATION_EXTERN
NSString
*
const
RemoteCommandCenterDidClick
;
// 用户基础信息
// 用户基础信息
FOUNDATION_EXTERN
NSString
*
const
UserBasicInfo
;
FOUNDATION_EXTERN
NSString
*
const
UserBasicInfo
;
...
...
DreamSleep/DreamSleep/Basement/Utils/DSConstUtil.m
查看文件 @
bfdcabe
...
@@ -27,6 +27,8 @@ NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti";
...
@@ -27,6 +27,8 @@ NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti";
NSString
*
const
ExitCoaxSleep
=
@"ExitCoaxSleepNoti"
;
NSString
*
const
ExitCoaxSleep
=
@"ExitCoaxSleepNoti"
;
NSString
*
const
NeedUpdateAICoach
=
@"NeedUpdateAICoachNoti"
;
NSString
*
const
NeedUpdateAICoach
=
@"NeedUpdateAICoachNoti"
;
NSString
*
const
NeedUpdateStartAI
=
@"NeedUpdateStartAINoti"
;
NSString
*
const
NeedUpdateStartAI
=
@"NeedUpdateStartAINoti"
;
NSString
*
const
UnlockAudioSuccess
=
@"UnlockAudioSuccessNoti"
;
NSString
*
const
RemoteCommandCenterDidClick
=
@"RemoteCommandCenterDidClickNoti"
;
NSString
*
const
UserBasicInfo
=
@"UserBasicInfo"
;
NSString
*
const
UserBasicInfo
=
@"UserBasicInfo"
;
...
...
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/CourseDetailController.m
查看文件 @
bfdcabe
...
@@ -45,9 +45,12 @@
...
@@ -45,9 +45,12 @@
if
(
self
.
isFromPlayer
==
NO
)
{
if
(
self
.
isFromPlayer
==
NO
)
{
// 给音频列表页面添加通知(从播放页面跳转到音频列表),通知发送时机:音频列表(从播放页面跳转到音频列表)登录成功后
// 给音频列表页面添加通知(从播放页面跳转到音频列表),通知发送时机:音频列表(从播放页面跳转到音频列表)登录成功后
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
refreshOriAudioList
)
name
:
@"UnlockAudioSuccessNoti"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
refreshOriAudioList
)
name
:
UnlockAudioSuccess
object
:
nil
];
}
}
// 监听息屏页面点击播放、上一首、下一首点击通知,用于更新当前播放列表正在播放的音频UI状态
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
updateListNoti
:
)
name
:
RemoteCommandCenterDidClick
object
:
nil
];
NSString
*
eventID
=
self
.
courseType
==
CourseTypeSafe
?
Meditation_Click
:
Relax_Music_Click
;
NSString
*
eventID
=
self
.
courseType
==
CourseTypeSafe
?
Meditation_Click
:
Relax_Music_Click
;
NSString
*
entranceName
=
self
.
courseType
==
CourseTypeSafe
?
@"首页-舒眠课程"
:
@"首页-助眠音乐"
;
NSString
*
entranceName
=
self
.
courseType
==
CourseTypeSafe
?
@"首页-舒眠课程"
:
@"首页-助眠音乐"
;
if
(
self
.
entrance
==
EntranceCourseList
)
{
if
(
self
.
entrance
==
EntranceCourseList
)
{
...
@@ -60,8 +63,10 @@
...
@@ -60,8 +63,10 @@
-
(
void
)
dealloc
{
-
(
void
)
dealloc
{
if
(
self
.
isFromPlayer
==
NO
)
{
if
(
self
.
isFromPlayer
==
NO
)
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
@"UnlockAudioSuccessNoti"
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UnlockAudioSuccess
object
:
nil
];
}
}
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
RemoteCommandCenterDidClick
object
:
nil
];
}
}
-
(
void
)
getAudiosData
{
-
(
void
)
getAudiosData
{
...
@@ -73,6 +78,12 @@
...
@@ -73,6 +78,12 @@
}];
}];
}
}
-
(
void
)
updateListNoti
:
(
NSNotification
*
)
noti
{
NSInteger
playingIndex
=
[
noti
.
userInfo
[
@"playingIndex"
]
integerValue
];
self
.
playingIndex
=
playingIndex
;
[
self
.
audioListView
reloadData
];
}
#pragma mark - Actions
#pragma mark - Actions
-
(
void
)
backAction
{
-
(
void
)
backAction
{
[
super
backAction
];
[
super
backAction
];
...
@@ -122,7 +133,7 @@
...
@@ -122,7 +133,7 @@
[
self
.
unlockBtn
setTitle
:
@"开始第一节"
forState
:
UIControlStateNormal
];
[
self
.
unlockBtn
setTitle
:
@"开始第一节"
forState
:
UIControlStateNormal
];
[
self
getAudiosData
];
[
self
getAudiosData
];
if
(
self
.
isFromPlayer
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"UnlockAudioSuccessNoti"
object
:
nil
];
}
if
(
self
.
isFromPlayer
)
{
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
UnlockAudioSuccess
object
:
nil
];
}
}
}
#pragma mark - 刷新最开始的音频列表
#pragma mark - 刷新最开始的音频列表
...
...
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/MusicPlayerController.m
查看文件 @
bfdcabe
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#import <FSAudioController.h>
#import <FSAudioController.h>
#import "SubAudioModel.h"
#import "SubAudioModel.h"
#import "CourseDetailController.h"
#import "CourseDetailController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface
MusicPlayerController
()
<
MusicPlayerViewDelegate
,
CourseDetailControllerDelegate
>
@interface
MusicPlayerController
()
<
MusicPlayerViewDelegate
,
CourseDetailControllerDelegate
>
@property
(
nonatomic
,
strong
)
MusicPlayerView
*
playerView
;
@property
(
nonatomic
,
strong
)
MusicPlayerView
*
playerView
;
...
@@ -23,7 +24,12 @@
...
@@ -23,7 +24,12 @@
@property
(
nonatomic
,
assign
)
FSAudioStreamState
streamState
;
@property
(
nonatomic
,
assign
)
FSAudioStreamState
streamState
;
@end
@end
@implementation
MusicPlayerController
@implementation
MusicPlayerController
{
// 控制中心信息
NSMutableDictionary
*
_remoteInfoDictionary
;
// 是否进入后台
BOOL
_isBackground
;
}
-
(
void
)
loadView
{
-
(
void
)
loadView
{
self
.
view
=
self
.
playerView
;
self
.
view
=
self
.
playerView
;
...
@@ -64,6 +70,7 @@
...
@@ -64,6 +70,7 @@
case
kFsAudioStreamPlaying
:
case
kFsAudioStreamPlaying
:
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
DSLog
(
@"播放ing..."
);
DSLog
(
@"播放ing..."
);
[
weakSelf
didClickRemoteCommandCenter
];
break
;
break
;
case
kFsAudioStreamFailed
:
case
kFsAudioStreamFailed
:
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
[
UIApplication
sharedApplication
].
networkActivityIndicatorVisible
=
NO
;
...
@@ -92,11 +99,129 @@
...
@@ -92,11 +99,129 @@
TimerProxy
*
proxy
=
[
TimerProxy
proxyWithTarget
:
self
];
TimerProxy
*
proxy
=
[
TimerProxy
proxyWithTarget
:
self
];
self
.
progressTimer
=
[
CADisplayLink
displayLinkWithTarget
:
proxy
selector
:
@selector
(
updateProgress
)];
self
.
progressTimer
=
[
CADisplayLink
displayLinkWithTarget
:
proxy
selector
:
@selector
(
updateProgress
)];
[
self
.
progressTimer
addToRunLoop
:[
NSRunLoop
mainRunLoop
]
forMode
:
NSRunLoopCommonModes
];
[
self
.
progressTimer
addToRunLoop
:[
NSRunLoop
mainRunLoop
]
forMode
:
NSRunLoopCommonModes
];
[
self
addPlayerObserver
];
[
self
addRemoteControlHandler
];
}
}
-
(
void
)
dealloc
{
-
(
void
)
dealloc
{
[
self
.
progressTimer
invalidate
];
[
self
.
progressTimer
invalidate
];
self
.
progressTimer
=
nil
;
self
.
progressTimer
=
nil
;
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
[[
UIApplication
sharedApplication
]
endReceivingRemoteControlEvents
];
MPRemoteCommandCenter
*
center
=
[
MPRemoteCommandCenter
sharedCommandCenter
];
[[
center
playCommand
]
removeTarget
:
self
];
[[
center
pauseCommand
]
removeTarget
:
self
];
[[
center
nextTrackCommand
]
removeTarget
:
self
];
[[
center
previousTrackCommand
]
removeTarget
:
self
];
[
center
.
changePlaybackPositionCommand
removeTarget
:
self
];
}
-
(
void
)
addPlayerObserver
{
// 将要进入后台
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
playerWillResignActive
)
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
// 已经进入前台
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
playerDidEnterForeground
)
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
}
-
(
void
)
playerWillResignActive
{
_isBackground
=
YES
;
}
-
(
void
)
playerDidEnterForeground
{
_isBackground
=
NO
;
}
#pragma mark - 息屏播放(通知栏、锁屏界面)
-
(
void
)
addPlayingCenterInfo
{
_remoteInfoDictionary
=
[
NSMutableDictionary
dictionary
];
SubAudioModel
*
audioModel
=
self
.
playAudios
[
self
.
currentIndex
];
_remoteInfoDictionary
[
MPMediaItemPropertyTitle
]
=
audioModel
.
audio_name
;
_remoteInfoDictionary
[
MPMediaItemPropertyAlbumTitle
]
=
@"小梦睡眠"
;
NSData
*
imageData
=
[
NSData
dataWithContentsOfURL
:[
NSURL
URLWithString
:
audioModel
.
audio_pic
]];
UIImage
*
artworkImg
=
[
UIImage
imageWithData
:
imageData
];
MPMediaItemArtwork
*
artwork
=
[[
MPMediaItemArtwork
alloc
]
initWithBoundsSize
:
artworkImg
.
size
requestHandler
:
^
UIImage
*
_Nonnull
(
CGSize
size
)
{
return
artworkImg
;
}];
_remoteInfoDictionary
[
MPMediaItemPropertyArtwork
]
=
artwork
;
_remoteInfoDictionary
[
MPNowPlayingInfoPropertyPlaybackRate
]
=
[
NSNumber
numberWithFloat
:
1
.
0
];
[
MPNowPlayingInfoCenter
defaultCenter
].
nowPlayingInfo
=
_remoteInfoDictionary
;
}
-
(
void
)
updatePlayingCenterInfo
{
if
(
!
_isBackground
)
{
return
;}
_remoteInfoDictionary
[
MPNowPlayingInfoPropertyElapsedPlaybackTime
]
=
[
NSNumber
numberWithDouble
:
self
.
audioStream
.
currentTimePlayed
.
playbackTimeInSeconds
];
_remoteInfoDictionary
[
MPMediaItemPropertyPlaybackDuration
]
=
[
NSNumber
numberWithDouble
:
self
.
audioStream
.
duration
.
playbackTimeInSeconds
];
[
MPNowPlayingInfoCenter
defaultCenter
].
nowPlayingInfo
=
_remoteInfoDictionary
;
}
-
(
void
)
addRemoteControlHandler
{
[[
UIApplication
sharedApplication
]
beginReceivingRemoteControlEvents
];
MPRemoteCommandCenter
*
center
=
[
MPRemoteCommandCenter
sharedCommandCenter
];
[
self
addRemoteCommand
:
center
.
playCommand
selector
:
@selector
(
play
)];
[
self
addRemoteCommand
:
center
.
pauseCommand
selector
:
@selector
(
pause
)];
[
self
addRemoteCommand
:
center
.
previousTrackCommand
selector
:
@selector
(
last
)];
[
self
addRemoteCommand
:
center
.
nextTrackCommand
selector
:
@selector
(
next
)];
}
-
(
void
)
addRemoteCommand
:
(
MPRemoteCommand
*
)
command
selector
:
(
SEL
)
selector
{
WS
(
weaksSelf
);
[
command
addTargetWithHandler
:
^
MPRemoteCommandHandlerStatus
(
MPRemoteCommandEvent
*
_Nonnull
event
)
{
if
([
weaksSelf
respondsToSelector
:
selector
])
{
IMP
imp
=
[
weaksSelf
methodForSelector
:
selector
];
void
(
*
func
)(
id
,
SEL
)
=
(
void
*
)
imp
;
func
(
weaksSelf
,
selector
);
}
return
MPRemoteCommandHandlerStatusSuccess
;
}];
}
-
(
void
)
play
{
if
(
self
.
streamState
==
kFsAudioStreamStopped
||
self
.
streamState
==
kFsAudioStreamRetrievingURL
)
{
[
self
.
audioStream
play
];
}
else
if
(
self
.
streamState
==
kFsAudioStreamPaused
)
{
// 恢复播放
[
self
.
audioStream
pause
];
}
[
self
didClickRemoteCommandCenter
];
}
-
(
void
)
pause
{
if
(
self
.
streamState
==
kFsAudioStreamPlaying
)
{
// 暂停播放
[
self
.
audioStream
pause
];
}
[
self
didClickRemoteCommandCenter
];
}
-
(
void
)
last
{
if
(
self
.
currentIndex
-
1
<
0
)
{
[
DSProgressHUD
showToast
:
@"没有上一首了"
];
return
;
}
self
.
currentIndex
--
;
[
self
launchPlayer
];
}
-
(
void
)
next
{
if
(
self
.
currentIndex
+
1
>=
self
.
playAudios
.
count
)
{
[
DSProgressHUD
showToast
:
@"没有下一首了"
];
return
;
}
self
.
currentIndex
++
;
[
self
launchPlayer
];
}
-
(
void
)
didClickRemoteCommandCenter
{
NSInteger
playingIndex
=
self
.
audioStream
.
isPlaying
?
self
.
currentIndex
:
-
1
;
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
RemoteCommandCenterDidClick
object
:
nil
userInfo
:
@{
@"playingIndex"
:
@
(
playingIndex
)}];
}
}
#pragma mark - private
#pragma mark - private
...
@@ -108,6 +233,8 @@
...
@@ -108,6 +233,8 @@
// 更新音频播放进度、音频当前播放时间、音频总时间
// 更新音频播放进度、音频当前播放时间、音频总时间
[
self
.
playerView
updateProgress
:
cur
.
position
currentTime
:[
NSString
stringWithFormat
:
@"%02i:%02i"
,
cur
.
minute
,
cur
.
second
]
totalTime
:
[
NSString
stringWithFormat
:
@"%02i:%02i"
,
end
.
minute
,
end
.
second
]];
[
self
.
playerView
updateProgress
:
cur
.
position
currentTime
:[
NSString
stringWithFormat
:
@"%02i:%02i"
,
cur
.
minute
,
cur
.
second
]
totalTime
:
[
NSString
stringWithFormat
:
@"%02i:%02i"
,
end
.
minute
,
end
.
second
]];
[
self
updatePlayingCenterInfo
];
}
}
-
(
void
)
audioStreamPlaybackCompleted
{
-
(
void
)
audioStreamPlaybackCompleted
{
...
@@ -137,13 +264,15 @@
...
@@ -137,13 +264,15 @@
}
}
-
(
void
)
launchPlayer
{
-
(
void
)
launchPlayer
{
// 不是正在播放的状态需要先停止
[
self
.
audioStream
stop
];
if
(
self
.
audioStream
.
isPlaying
==
NO
)
{
[
self
.
audioStream
stop
];
}
if
(
self
.
currentIndex
>=
self
.
playAudios
.
count
)
{
return
;
}
if
(
self
.
currentIndex
>=
self
.
playAudios
.
count
)
{
return
;
}
SubAudioModel
*
audioModel
=
self
.
playAudios
[
self
.
currentIndex
];
SubAudioModel
*
audioModel
=
self
.
playAudios
[
self
.
currentIndex
];
[
self
.
playerView
updatePlayerView
:
audioModel
];
[
self
.
playerView
updatePlayerView
:
audioModel
];
[
self
.
audioStream
playFromURL
:[
NSURL
URLWithString
:
audioModel
.
audio_url
]];
[
self
.
audioStream
playFromURL
:[
NSURL
URLWithString
:
audioModel
.
audio_url
]];
// 设置音频锁屏界面信息
[
self
addPlayingCenterInfo
];
}
}
#pragma mark - MusicPlayerViewDelegate
#pragma mark - MusicPlayerViewDelegate
...
@@ -170,12 +299,7 @@
...
@@ -170,12 +299,7 @@
switch
(
item
.
tag
)
{
switch
(
item
.
tag
)
{
case
1
:
// 上一首
case
1
:
// 上一首
{
{
if
(
self
.
currentIndex
-
1
<
0
)
{
[
self
last
];
[
DSProgressHUD
showToast
:
@"没有上一首了"
];
return
;
}
self
.
currentIndex
--
;
[
self
launchPlayer
];
}
}
break
;
break
;
case
2
:
// 播放暂停
case
2
:
// 播放暂停
...
@@ -193,12 +317,7 @@
...
@@ -193,12 +317,7 @@
break
;
break
;
case
3
:
// 下一首
case
3
:
// 下一首
{
{
if
(
self
.
currentIndex
+
1
>=
self
.
playAudios
.
count
)
{
[
self
next
];
[
DSProgressHUD
showToast
:
@"没有下一首了"
];
return
;
}
self
.
currentIndex
++
;
[
self
launchPlayer
];
}
}
break
;
break
;
default
:
default
:
...
...
DreamSleep/DreamSleep/Resource/Assets.xcassets/.DS_Store
查看文件 @
bfdcabe
此文件类型无法预览
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论