Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
ff58c21e
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ff58c21e
编写于
9月 05, 2023
作者:
Z
zhangkai269
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
systemSoundManager arkts 整改
Signed-off-by:
N
zhangkai269
<
zhangkai269@huawei.com
>
上级
295273c3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
145 addition
and
103 deletion
+145
-103
zh-cn/application-dev/reference/apis/js-apis-inner-multimedia-ringtonePlayer.md
...reference/apis/js-apis-inner-multimedia-ringtonePlayer.md
+102
-72
zh-cn/application-dev/reference/apis/js-apis-systemSoundManager.md
...lication-dev/reference/apis/js-apis-systemSoundManager.md
+43
-31
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inner-multimedia-ringtonePlayer.md
浏览文件 @
ff58c21e
...
...
@@ -12,7 +12,7 @@ ringtonePlayer需要和[@ohos.multimedia.systemSoundManager](js-apis-systemSound
## 导入模块
```
j
s
```
t
s
import
systemSoundManager
from
'
@ohos.multimedia.systemSoundManager
'
;
```
...
...
@@ -45,8 +45,8 @@ import systemSoundManager from '@ohos.multimedia.systemSoundManager';
**示例:**
```
j
s
let
state
=
systemRingtonePlayer
.
state
;
```
t
s
let
state
:
media
.
AVPlayerState
=
systemRingtonePlayer
.
state
;
```
### getTitle
...
...
@@ -67,8 +67,10 @@ getTitle(callback: AsyncCallback<string>): void
**示例:**
```
js
systemRingtonePlayer
.
getTitle
((
err
,
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
getTitle
((
err
:
BusinessError
,
value
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get system ringtone title.
${
err
}
`
);
return
;
...
...
@@ -95,10 +97,12 @@ getTitle(): Promise<string>
**示例:**
```
js
systemRingtonePlayer
.
getTitle
().
then
((
value
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
getTitle
().
then
((
value
:
string
)
=>
{
console
.
info
(
`Promise returned to indicate that the value of the system ringtone title is obtained
${
value
}
.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to get the system ringtone title
${
err
}
`
);
});
```
...
...
@@ -121,12 +125,13 @@ getAudioRendererInfo(callback: AsyncCallback<audio.AudioRendererInfo>): vo
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
null
;
systemRingtonePlayer
.
getAudioRendererInfo
((
err
,
value
)
=>
{
systemRingtonePlayer
.
getAudioRendererInfo
((
err
:
BusinessError
,
value
:
audio
.
AudioRendererInfo
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get ringtone AudioRendererInfo.
${
err
}
`
);
return
;
...
...
@@ -154,15 +159,16 @@ getAudioRendererInfo(): Promise<audio.AudioRendererInfo>
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
audioRendererInfo
:
audio
.
AudioRendererInfo
=
null
;
systemRingtonePlayer
.
getAudioRendererInfo
().
then
((
value
)
=>
{
systemRingtonePlayer
.
getAudioRendererInfo
().
then
((
value
:
audio
.
AudioRendererInfo
)
=>
{
console
.
info
(
`Promise returned to indicate that the value of the ringtone AudioRendererInfo is obtained
${
value
}
.`
);
audioRendererInfo
=
value
;
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to get the ringtone AudioRendererInfo
${
err
}
`
);
});
```
...
...
@@ -186,10 +192,16 @@ configure(options: RingtoneOptions, callback: AsyncCallback<void>): void
**示例:**
```
js
let
ringtoneOptions
=
{
volume
:
0.5
,
loop
:
true
};
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
RingtoneOptions
{
volume
:
number
;
loop
:
boolean
;
}
let
ringtoneOptions
:
RingtoneOptions
=
{
volume
:
0.5
,
loop
:
true
};
systemRingtonePlayer
.
configure
(
ringtoneOptions
,
(
err
)
=>
{
systemRingtonePlayer
.
configure
(
ringtoneOptions
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to configure ringtone options.
${
err
}
`
);
return
;
...
...
@@ -222,12 +234,18 @@ configure(options: RingtoneOptions): Promise<void>
**示例:**
```
js
let
ringtoneOptions
=
{
volume
:
0.5
,
loop
:
true
};
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
class
RingtoneOptions
{
volume
:
number
;
loop
:
boolean
;
}
let
ringtoneOptions
:
RingtoneOptions
=
{
volume
:
0.5
,
loop
:
true
};
systemRingtonePlayer
.
configure
(
ringtoneOptions
).
then
(()
=>
{
console
.
info
(
`Promise returned to indicate a successful setting of ringtone options.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to configure ringtone options.
${
err
}
`
);
});
```
...
...
@@ -250,8 +268,10 @@ start(callback: AsyncCallback<void>): void
**示例:**
```
js
systemRingtonePlayer
.
start
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
start
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to start playing ringtone.
${
err
}
`
);
return
;
...
...
@@ -278,10 +298,12 @@ start(): Promise<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
start
().
then
(()
=>
{
console
.
info
(
`Promise returned to indicate a successful starting of ringtone.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to start playing ringtone.
${
err
}
`
);
});
```
...
...
@@ -304,8 +326,10 @@ stop(callback: AsyncCallback<void>): void
**示例:**
```
js
systemRingtonePlayer
.
stop
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
stop
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to stop playing ringtone.
${
err
}
`
);
return
;
...
...
@@ -332,10 +356,12 @@ stop(): Promise<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
stop
().
then
(()
=>
{
console
.
info
(
`Promise returned to indicate a successful stopping of ringtone.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to stop playing ringtone.
${
err
}
`
);
});
```
...
...
@@ -358,8 +384,10 @@ release(callback: AsyncCallback<void>): void
**示例:**
```
js
systemRingtonePlayer
.
release
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
release
((
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to release ringtone player.
${
err
}
`
);
return
;
...
...
@@ -386,10 +414,12 @@ release(): Promise<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemRingtonePlayer
.
release
().
then
(()
=>
{
console
.
info
(
`Promise returned to indicate a successful releasing of ringtone player.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to release ringtone player.
${
err
}
`
);
});
```
...
...
@@ -422,50 +452,50 @@ on(type: 'audioInterrupt', callback: Callback<audio.InterruptEvent>): void
**示例:**
```
j
s
```
t
s
import
audio
from
'
@ohos.multimedia.audio
'
;
let
isPlaying
;
// 标识符,表示是否正在渲染
let
isDucked
;
// 标识符,表示是否被降低音量
systemRingtonePlayer
.
on
(
'
audioInterrupt
'
,
async
(
interruptEvent
)
=>
{
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_FORCE
)
{
// 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等
switch
(
interruptEvent
.
hintType
)
{
case
audio
.
InterruptHint
.
INTERRUPT_HINT_PAUSE
:
// 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
console
.
info
(
'
Force paused. Update playing status and stop writing
'
);
isPlaying
=
false
;
// 简化处理,代表应用切换至暂停状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_STOP
:
// 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发
console
.
info
(
'
Force stopped. Update playing status and stop writing
'
);
isPlaying
=
false
;
// 简化处理,代表应用切换至暂停状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_DUCK
:
// 音频流已被降低音量渲染
console
.
info
(
'
Force ducked. Update volume status
'
);
isDucked
=
true
;
// 简化处理,代表应用更新音量状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_UNDUCK
:
// 音频流已被恢复正常音量渲染
console
.
info
(
'
Force ducked. Update volume status
'
);
isDucked
=
false
;
// 简化处理,代表应用更新音量状态的若干操作
break
;
default
:
break
;
let
isPlaying
:
boolean
;
// 标识符,表示是否正在渲染
let
isDucked
:
boolean
;
// 标识符,表示是否被降低音量
systemRingtonePlayer
.
on
(
'
audioInterrupt
'
,
async
(
interruptEvent
:
audio
.
InterruptEvent
)
=>
{
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_FORCE
)
{
// 由系统进行操作,强制打断音频渲染,应用需更新自身状态及显示内容等
switch
(
interruptEvent
.
hintType
)
{
case
audio
.
InterruptHint
.
INTERRUPT_HINT_PAUSE
:
// 音频流已被暂停,临时失去焦点,待可重获焦点时会收到resume对应的interruptEvent
console
.
info
(
'
Force paused. Update playing status and stop writing
'
);
isPlaying
=
false
;
// 简化处理,代表应用切换至暂停状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_STOP
:
// 音频流已被停止,永久失去焦点,若想恢复渲染,需用户主动触发
console
.
info
(
'
Force stopped. Update playing status and stop writing
'
);
isPlaying
=
false
;
// 简化处理,代表应用切换至暂停状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_DUCK
:
// 音频流已被降低音量渲染
console
.
info
(
'
Force ducked. Update volume status
'
);
isDucked
=
true
;
// 简化处理,代表应用更新音量状态的若干操作
break
;
case
audio
.
InterruptHint
.
INTERRUPT_HINT_UNDUCK
:
// 音频流已被恢复正常音量渲染
console
.
info
(
'
Force ducked. Update volume status
'
);
isDucked
=
false
;
// 简化处理,代表应用更新音量状态的若干操作
break
;
default
:
break
;
}
}
else
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_SHARE
)
{
// 由应用进行操作,应用可以自主选择响应操作或忽略该事件
switch
(
interruptEvent
.
hintType
)
{
case
audio
.
InterruptHint
.
INTERRUPT_HINT_RESUME
:
// 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染)
console
.
info
(
'
Resume force paused renderer or ignore
'
);
// 若选择继续渲染,需在此处主动执行开始渲染的若干操作
break
;
default
:
break
;
}
else
if
(
interruptEvent
.
forceType
==
audio
.
InterruptForceType
.
INTERRUPT_SHARE
)
{
// 由应用进行操作,应用可以自主选择响应操作或忽略该事件
switch
(
interruptEvent
.
hintType
)
{
case
audio
.
InterruptHint
.
INTERRUPT_HINT_RESUME
:
// 建议应用继续渲染(说明音频流此前被强制暂停,临时失去焦点,现在可以恢复渲染)
console
.
info
(
'
Resume force paused renderer or ignore
'
);
// 若选择继续渲染,需在此处主动执行开始渲染的若干操作
break
;
default
:
break
;
}
}
}
});
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-systemSoundManager.md
浏览文件 @
ff58c21e
...
...
@@ -10,7 +10,7 @@
## 导入模块
```
j
s
```
t
s
import
systemSoundManager
from
'
@ohos.multimedia.systemSoundManager
'
;
```
...
...
@@ -44,8 +44,8 @@ getSystemSoundManager(): SystemSoundManager
|
[
SystemSoundManager
](
#systemsoundmanager
)
| 系统声音管理类。 |
**示例:**
```
j
s
let
systemSoundManagerInstance
=
systemSoundManager
.
getSystemSoundManager
();
```
t
s
let
systemSoundManagerInstance
:
systemSoundManager
.
SystemSoundManager
=
systemSoundManager
.
getSystemSoundManager
();
```
## SystemSoundManager
...
...
@@ -73,12 +73,14 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType, callback
**示例:**
```
js
let
context
=
this
.
context
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
context
:
Context
=
this
.
context
;
let
uri
=
'
file://data/test.wav
'
;
// 需更改为目标铃声文件的uri
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
systemSoundManagerInstance
.
setSystemRingtoneUri
(
context
,
uri
,
type
,
(
err
)
=>
{
systemSoundManagerInstance
.
setSystemRingtoneUri
(
context
,
uri
,
type
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to set system ringtone uri.
${
err
}
`
);
return
;
...
...
@@ -113,14 +115,16 @@ setSystemRingtoneUri(context: Context, uri: string, type: RingtoneType): Promise
**示例:**
```
js
let
context
=
this
.
context
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
context
:
Context
=
this
.
context
;
let
uri
=
'
file://data/test.wav
'
;
// 需更改为目标铃声文件的uri
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
systemSoundManagerInstance
.
setSystemRingtoneUri
(
context
,
uri
,
type
).
then
(()
=>
{
console
.
info
(
`Promise returned to indicate a successful setting of the system ringtone uri.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to set the system ringtone uri
${
err
}
`
);
});
```
...
...
@@ -145,11 +149,13 @@ getSystemRingtoneUri(context: Context, type: RingtoneType, callback: AsyncCallba
**示例:**
```
js
let
context
=
this
.
context
;
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
context
:
Context
=
this
.
context
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
systemSoundManagerInstance
.
getSystemRingtoneUri
(
context
,
type
,
(
err
,
value
)
=>
{
systemSoundManagerInstance
.
getSystemRingtoneUri
(
context
,
type
,
(
err
:
BusinessError
,
value
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get system ringtone uri.
${
err
}
`
);
return
;
...
...
@@ -183,13 +189,15 @@ getSystemRingtoneUri(context: Context, type: RingtoneType): Promise<string>
**示例:**
```
js
let
context
=
this
.
context
;
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
systemSoundManagerInstance
.
getSystemRingtoneUri
(
context
,
type
).
then
((
value
)
=>
{
let
context
:
Context
=
this
.
context
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
systemSoundManagerInstance
.
getSystemRingtoneUri
(
context
,
type
).
then
((
value
:
string
)
=>
{
console
.
info
(
`Promise returned to indicate that the value of the system ringtone uri is obtained
${
value
}
.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to get the system ringtone uri
${
err
}
`
);
});
```
...
...
@@ -214,12 +222,14 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType, callback: AsyncCal
**示例:**
```
js
let
context
=
this
.
context
;
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
systemRingtonePlayer
=
null
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
context
:
Context
=
this
.
context
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
systemRingtonePlayer
:
systemSoundManager
.
RingtonePlayer
=
null
;
systemSoundManagerInstance
.
getSystemRingtonePlayer
(
context
,
type
,
(
err
,
value
)
=>
{
systemSoundManagerInstance
.
getSystemRingtonePlayer
(
context
,
type
,
(
err
:
BusinessError
,
value
:
systemSoundManager
.
RingtonePlayer
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to get system ringtone player.
${
err
}
`
);
return
;
...
...
@@ -254,15 +264,17 @@ getSystemRingtonePlayer(context: Context, type: RingtoneType): Promise<Ringto
**示例:**
```
js
let
context
=
this
.
context
;
let
type
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
systemRingtonePlayer
=
null
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
context
:
Context
=
this
.
context
;
let
type
:
systemSoundManager
.
RingtoneType
=
systemSoundManager
.
RingtoneType
.
RINGTONE_TYPE_DEFAULT
;
let
systemRingtonePlayer
:
systemSoundManager
.
RingtonePlayer
=
null
;
systemSoundManagerInstance
.
getSystemRingtonePlayer
(
context
,
type
).
then
((
value
)
=>
{
systemSoundManagerInstance
.
getSystemRingtonePlayer
(
context
,
type
).
then
((
value
:
systemSoundManager
.
RingtonePlayer
)
=>
{
console
.
info
(
`Promise returned to indicate that the value of the system ringtone player is obtained.`
);
systemRingtonePlayer
=
value
;
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to get the system ringtone player
${
err
}
`
);
});
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录