Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit fa99d337
由
cgx
编写于
2022-06-21 18:12:32 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
优化息屏播放
1 个父辈
000404e3
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
1 行删除
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/MusicPlayerController.m
DreamSleep/DreamSleep/Class/HomeModule/Course/Controller/MusicPlayerController.m
查看文件 @
fa99d33
...
...
@@ -11,6 +11,7 @@
#import "SubAudioModel.h"
#import "CourseDetailController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
@interface
MusicPlayerController
()
<
MusicPlayerViewDelegate
,
CourseDetailControllerDelegate
>
@property
(
nonatomic
,
strong
)
MusicPlayerView
*
playerView
;
...
...
@@ -110,6 +111,7 @@
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
AVAudioSessionInterruptionNotification
object
:
nil
];
[[
UIApplication
sharedApplication
]
endReceivingRemoteControlEvents
];
MPRemoteCommandCenter
*
center
=
[
MPRemoteCommandCenter
sharedCommandCenter
];
...
...
@@ -125,6 +127,11 @@
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
playerWillResignActive
)
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
// 已经进入前台
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
playerDidEnterForeground
)
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
// 监听播放器被打断(别的软件播放音乐,来电话)
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
playerAudioBeInterrupted
:
)
name
:
AVAudioSessionInterruptionNotification
object
:
[
AVAudioSession
sharedInstance
]];
}
-
(
void
)
playerWillResignActive
{
...
...
@@ -135,6 +142,17 @@
_isBackground
=
NO
;
}
-
(
void
)
playerAudioBeInterrupted
:
(
NSNotification
*
)
notification
{
NSDictionary
*
userInfo
=
notification
.
userInfo
;
if
([
userInfo
[
AVAudioSessionInterruptionTypeKey
]
integerValue
]
==
1
)
{
// 打断开始
[
self
pause
];
}
else
{
// 打断结束
if
([
userInfo
[
AVAudioSessionInterruptionOptionKey
]
unsignedIntegerValue
]
==
1
)
{
[
self
play
];
}
}
}
#pragma mark - 息屏播放(通知栏、锁屏界面)
-
(
void
)
addPlayingCenterInfo
{
_remoteInfoDictionary
=
[
NSMutableDictionary
dictionary
];
...
...
@@ -154,7 +172,7 @@
}
-
(
void
)
updatePlayingCenterInfo
{
if
(
!
_isBackground
)
{
return
;
}
if
(
!
_isBackground
)
{
return
;
}
_remoteInfoDictionary
[
MPNowPlayingInfoPropertyElapsedPlaybackTime
]
=
[
NSNumber
numberWithDouble
:
self
.
audioStream
.
currentTimePlayed
.
playbackTimeInSeconds
];
_remoteInfoDictionary
[
MPMediaItemPropertyPlaybackDuration
]
=
[
NSNumber
numberWithDouble
:
self
.
audioStream
.
duration
.
playbackTimeInSeconds
];
[
MPNowPlayingInfoCenter
defaultCenter
].
nowPlayingInfo
=
_remoteInfoDictionary
;
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论