Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 8874eeb5
由
cgx
编写于
2022-05-23 10:30:35 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
修复白噪音正在播放被其他APP音频中断播放状态问题
1 个父辈
319ab8c5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
0 行删除
DreamSleep/DreamSleep/Class/HomeModule/WhiteNoise/Model/NoisePlayerManager.m
DreamSleep/DreamSleep/Class/HomeModule/WhiteNoise/Model/NoisePlayerManager.m
查看文件 @
8874eeb
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
#import "NoisePlayerManager.h"
#import "NoisePlayerManager.h"
#import <AVFoundation/AVFoundation.h>
@interface
NoisePlayerManager
()
@interface
NoisePlayerManager
()
/// 临时操作使用的可变数组
/// 临时操作使用的可变数组
...
@@ -19,6 +20,8 @@ SingletonM(NoisePlayerManager)
...
@@ -19,6 +20,8 @@ SingletonM(NoisePlayerManager)
_isPlaying
=
isPlaying
;
_isPlaying
=
isPlaying
;
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"playStatusNoti"
object
:
nil
userInfo
:
@{
@"isPlaying"
:
@
(
self
.
isPlaying
)}];
[[
NSNotificationCenter
defaultCenter
]
postNotificationName
:
@"playStatusNoti"
object
:
nil
userInfo
:
@{
@"isPlaying"
:
@
(
self
.
isPlaying
)}];
[
self
addNoti
];
}
}
-
(
NSMutableArray
*
)
tmpArry
{
-
(
NSMutableArray
*
)
tmpArry
{
...
@@ -28,6 +31,31 @@ SingletonM(NoisePlayerManager)
...
@@ -28,6 +31,31 @@ SingletonM(NoisePlayerManager)
return
_tmpArry
;
return
_tmpArry
;
}
}
-
(
void
)
addNoti
{
// 监听音频被其他APP打断通知
AVAudioSession
*
sessionInstance
=
[
AVAudioSession
sharedInstance
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
audioSessionWasInterrupted
:
)
name
:
AVAudioSessionInterruptionNotification
object
:
sessionInstance
];
NSError
*
error
=
nil
;
[
sessionInstance
setCategory
:
AVAudioSessionCategoryPlayback
error
:
&
error
];
if
(
nil
!=
error
)
{
DSLog
(
@"Error setting audio session category! %@"
,
error
);
}
else
{
[
sessionInstance
setActive
:
YES
error
:
&
error
];
if
(
nil
!=
error
)
DSLog
(
@"Error setting audio session active! %@"
,
error
);
}
}
-
(
void
)
removeNoti
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
name
:
AVAudioSessionInterruptionNotification
object
:
[
AVAudioSession
sharedInstance
]];
}
-
(
void
)
audioSessionWasInterrupted
:
(
NSNotification
*
)
notification
{
self
.
isPlaying
=
NO
;
}
-
(
NSArray
<
NoiseAudioCell
*>
*
)
playCellList
{
-
(
NSArray
<
NoiseAudioCell
*>
*
)
playCellList
{
return
[
self
.
tmpArry
copy
];
return
[
self
.
tmpArry
copy
];
}
}
...
@@ -41,6 +69,8 @@ SingletonM(NoisePlayerManager)
...
@@ -41,6 +69,8 @@ SingletonM(NoisePlayerManager)
[
item
play
];
[
item
play
];
}
}
self
.
isPlaying
=
isPlaying
;
self
.
isPlaying
=
isPlaying
;
[
self
addNoti
];
}
}
-
(
void
)
pauseAll
{
-
(
void
)
pauseAll
{
...
@@ -49,6 +79,8 @@ SingletonM(NoisePlayerManager)
...
@@ -49,6 +79,8 @@ SingletonM(NoisePlayerManager)
[
item
pause
];
[
item
pause
];
}
}
self
.
isPlaying
=
NO
;
self
.
isPlaying
=
NO
;
[
self
removeNoti
];
}
}
-
(
void
)
stopAll
{
-
(
void
)
stopAll
{
...
@@ -58,6 +90,8 @@ SingletonM(NoisePlayerManager)
...
@@ -58,6 +90,8 @@ SingletonM(NoisePlayerManager)
[
item
stop
];
[
item
stop
];
}
}
self
.
isPlaying
=
NO
;
self
.
isPlaying
=
NO
;
[
self
removeNoti
];
}
}
-
(
BOOL
)
addNoiseAudioCell
:
(
NoiseAudioCell
*
)
cell
{
-
(
BOOL
)
addNoiseAudioCell
:
(
NoiseAudioCell
*
)
cell
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论