@ohos.multimedia.avsession (媒体会话管理)

媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。

该模块提供以下媒体会话相关的常用功能:

  • AVSession : 会话,可用于设置元数据、播放状态信息等操作。
  • AVSessionController: 会话控制器,可用于查看会话ID,完成对会话发送命令及事件,获取会话元数据、播放状态信息等操作。
  • AVCastController: 投播控制器,可用于投播场景下,完成播放控制、远端播放状态监听、远端播放状态信息获取等操作。

说明:

本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import { avSession } from '@kit.AVSessionKit';

avSession.createAVSession10+

createAVSession(context: Context, tag: string, type: AVSessionType): Promise<AVSession>

创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
context Context 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。
tag string 会话的自定义名称。
type AVSessionType 会话类型。

返回值:

类型 说明
Promise<AVSession> Promise对象。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = getContext(this);
let sessionId: string;  // 供后续函数入参使用。

avSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => {
  currentAVSession = data;
  sessionId = currentAVSession.sessionId;
  console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
}).catch((err: BusinessError) => {
  console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
});

avSession.createAVSession10+

createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback<AVSession>): void

创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
context Context 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。
tag string 会话的自定义名称。
type AVSessionType 会话类型。
callback AsyncCallback<AVSession> 回调函数。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession;
let tag = "createNewSession";
let context: Context = getContext(this);
let sessionId: string;  // 供后续函数入参使用。

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
    sessionId = currentAVSession.sessionId;
    console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
  }
});

ProtocolType11+

远端设备支持的协议类型的枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 说明
TYPE_LOCAL11+ 0 本地设备,包括设备本身的内置扬声器或音频插孔、A2DP 设备。
TYPE_CAST_PLUS_STREAM11+ 2 Cast+的Stream模式。表示媒体正在其他设备上展示。
TYPE_DLNA12+ 4 DLNA协议。表示媒体正在其他设备上展示。

DistributedSessionType18+

远端分布式设备支持的会话类型。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 说明
TYPE_SESSION_REMOTE 0 远端设备会话。
TYPE_SESSION_MIGRATE_IN 1 迁移至本端的设备会话。
TYPE_SESSION_MIGRATE_OUT 2 迁移至远端的设备会话。

AVSessionType10+

type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'

当前会话支持的会话类型。

该类型可取的值为下表字符串。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

类型 说明
'audio' 音频
'video' 视频
'voice_call'11+ 音频通话。
'video_call'12+ 视频通话。

AVSession10+

调用avSession.createAVSession后,返回会话的实例,可以获得会话ID,完成设置元数据,播放状态信息等操作。

属性

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 可读 可写 说明
sessionId string AVSession对象唯一的会话标识。
sessionType AVSessionType AVSession会话类型。

示例:

let sessionId: string = currentAVSession.sessionId;
let sessionType: avSession.AVSessionType = currentAVSession.sessionType;

setAVMetadata10+

setAVMetadata(data: AVMetadata): Promise<void>

设置会话元数据。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
data AVMetadata 会话元数据。

返回值:

类型 说明
Promise<void> Promise对象。当元数据设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let metadata: avSession.AVMetadata = {
  assetId: "121278",
  title: "lose yourself",
  artist: "Eminem",
  author: "ST",
  album: "Slim shady",
  writer: "ST",
  composer: "ST",
  duration: 2222,
  mediaImage: "https://www.example.com/example.jpg",
  subtitle: "8 Mile",
  description: "Rap",
  // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。
  // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n
  lyric: "lrc格式歌词内容",
  // singleLyricText字段存储单条歌词文本,不包含时间戳。
  // 例如:"单条歌词内容"。
  singleLyricText: "单条歌词内容",
  previousAssetId: "121277",
  nextAssetId: "121279"
};
currentAVSession.setAVMetadata(metadata).then(() => {
  console.info('SetAVMetadata successfully');
}).catch((err: BusinessError) => {
  console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
});

setAVMetadata10+

setAVMetadata(data: AVMetadata, callback: AsyncCallback<void>): void

设置会话元数据。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
data AVMetadata 会话元数据。
callback AsyncCallback<void> 回调函数。当元数据设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let metadata: avSession.AVMetadata = {
  assetId: "121278",
  title: "lose yourself",
  artist: "Eminem",
  author: "ST",
  album: "Slim shady",
  writer: "ST",
  composer: "ST",
  duration: 2222,
  mediaImage: "https://www.example.com/example.jpg",
  subtitle: "8 Mile",
  description: "Rap",
  // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。
  // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n
  lyric: "lrc格式歌词内容",
  // singleLyricText字段存储单条歌词文本,不包含时间戳。
  // 例如:"单条歌词内容"。
  singleLyricText: "单条歌词内容",
  previousAssetId: "121277",
  nextAssetId: "121279"
};
currentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
  if (err) {
    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SetAVMetadata successfully');
  }
});

setCallMetadata11+

setCallMetadata(data: CallMetadata): Promise<void>

设置通话会话元数据。结果通过Promise异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
data CallMetadata 通话会话元数据。

返回值:

类型 说明
Promise<void> Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { image } from '@kit.ImageKit';
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
    let imageSource = await image.createImageSource(value.buffer);
    let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
    let calldata: avSession.CallMetadata = {
      name: "xiaoming",
      phoneNumber: "111xxxxxxxx",
      avatar: imagePixel
    };
currentAVSession.setCallMetadata(calldata).then(() => {
  console.info('setCallMetadata successfully');
}).catch((err: BusinessError) => {
  console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
});

setCallMetadata11+

setCallMetadata(data: CallMetadata, callback: AsyncCallback<void>): void

设置通话会话元数据。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
data CallMetadata 通话会话元数据。
callback AsyncCallback<void> 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { image } from '@kit.ImageKit';
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

async function setCallMetadata() {
  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
  let imageSource = await image.createImageSource(value.buffer);
  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
  let calldata: avSession.CallMetadata = {
    name: "xiaoming",
    phoneNumber: "111xxxxxxxx",
    avatar: imagePixel
  };
  currentAVSession.setCallMetadata(calldata, (err: BusinessError) => {
    if (err) {
      console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
      console.info('setCallMetadata successfully');
    }
  });
}

setAVCallState11+

setAVCallState(state: AVCallState): Promise<void>

设置通话状态。结果通过Promise异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
state AVCallState 通话状态。

返回值:

类型 说明
Promise<void> Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let calldata: avSession.AVCallState = {
  state: avSession.CallState.CALL_STATE_ACTIVE,
  muted: false
};
currentAVSession.setAVCallState(calldata).then(() => {
  console.info('setAVCallState successfully');
}).catch((err: BusinessError) => {
  console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
});

setAVCallState11+

setAVCallState(state: AVCallState, callback: AsyncCallback<void>): void

设置通话状态。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
state AVCallState 通话状态。
callback AsyncCallback<void> 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avcalldata: avSession.AVCallState = {
  state: avSession.CallState.CALL_STATE_ACTIVE,
  muted: false
};
currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => {
  if (err) {
    console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('setAVCallState successfully');
  }
});

setAVPlaybackState10+

setAVPlaybackState(state: AVPlaybackState): Promise<void>

设置会话播放状态。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
state AVPlaybackState 会话播放状态,包括状态、倍数、循环模式等信息。

返回值:

类型 说明
Promise<void> Promise对象。当播放状态设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let playbackState: avSession.AVPlaybackState = {
  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
  speed: 1.0,
  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
  bufferedTime:1000,
  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
  isFavorite:true
};
currentAVSession.setAVPlaybackState(playbackState).then(() => {
  console.info('SetAVPlaybackState successfully');
}).catch((err: BusinessError) => {
  console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
});

setAVPlaybackState10+

setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback<void>): void

设置会话播放状态。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
state AVPlaybackState 会话播放状态,包括状态、倍数、循环模式等信息。
callback AsyncCallback<void> 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let PlaybackState: avSession.AVPlaybackState = {
  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
  speed: 1.0,
  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
  bufferedTime:1000,
  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
  isFavorite:true
};
currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
  if (err) {
    console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SetAVPlaybackState successfully');
  }
});

setLaunchAbility10+

setLaunchAbility(ability: WantAgent): Promise<void>

设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
ability WantAgent 应用的相关属性信息,如bundleName,abilityName,deviceId等。

返回值:

类型 说明
Promise<void> Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { wantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// WantAgentInfo对象。
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: "deviceId",
      bundleName: "com.example.myapplication",
      abilityName: "EntryAbility",
      action: "action1",
      entities: ["entity1"],
      type: "MIMETYPE",
      uri: "key = {true,true,false}",
      parameters:
        {
          mykey0: 2222,
          mykey1: [1, 2, 3],
          mykey2: "[1, 2, 3]",
          mykey3: "ssssssssssssssssssssssssss",
          mykey4: [false, true, false],
          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
          mykey6: true
        }
    }
  ],
  operationType: wantAgent.OperationType.START_ABILITIES,
  requestCode: 0,
  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
  currentAVSession.setLaunchAbility(agent).then(() => {
    console.info('SetLaunchAbility successfully');
  }).catch((err: BusinessError) => {
    console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
  });
});

setLaunchAbility10+

setLaunchAbility(ability: WantAgent, callback: AsyncCallback<void>): void

设置一个WantAgent用于拉起会话的Ability。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
ability WantAgent 应用的相关属性信息,如bundleName,abilityName,deviceId等。
callback AsyncCallback<void> 回调函数。当Ability设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { wantAgent } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

// WantAgentInfo对象。
let wantAgentInfo: wantAgent.WantAgentInfo = {
  wants: [
    {
      deviceId: "deviceId",
      bundleName: "com.example.myapplication",
      abilityName: "EntryAbility",
      action: "action1",
      entities: ["entity1"],
      type: "MIMETYPE",
      uri: "key = {true,true,false}",
      parameters:
        {
          mykey0: 2222,
          mykey1: [1, 2, 3],
          mykey2: "[1, 2, 3]",
          mykey3: "ssssssssssssssssssssssssss",
          mykey4: [false, true, false],
          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
          mykey6: true
        }
    }
  ],
  operationType: wantAgent.OperationType.START_ABILITIES,
  requestCode: 0,
  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
  currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
    if (err) {
      console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
      console.info('SetLaunchAbility successfully');
    }
  });
});

dispatchSessionEvent10+

dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise<void>

媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容, 结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
event string 需要设置的会话事件的名称。
args {[key: string]: Object} 需要传递的会话事件内容。

说明: 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

返回值:

类型 说明
Promise<void> Promise对象。当事件设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
let eventName = "dynamic_lyric";
if (currentAVSession !== undefined) {
  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
    console.info('dispatchSessionEvent successfully');
  }).catch((err: BusinessError) => {
    console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
  })
}

dispatchSessionEvent10+

dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback<void>): void

媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容, 结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
event string 需要设置的会话事件的名称。
args {[key: string]: Object} 需要传递的会话事件内容。
callback AsyncCallback<void> 回调函数。当会话事件设置成功,err为undefined,否则返回错误对象。

说明:

参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
let eventName: string = "dynamic_lyric";
if (currentAVSession !== undefined) {
  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
    if (err) {
      console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
    }
  })
}

setAVQueueItems10+

setAVQueueItems(items: Array<AVQueueItem>): Promise<void>

设置媒体播放列表。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
items Array<AVQueueItem> 播放列表单项的队列,用以表示播放列表。

返回值:

类型 说明
Promise<void> Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { image } from '@kit.ImageKit';
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

async function setAVQueueItems() {
  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
  let imageSource = await image.createImageSource(value.buffer);
  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
  let queueItemDescription_1: avSession.AVMediaDescription = {
    assetId: '001',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    mediaImage : imagePixel,
    extras: {extras:'any'}
  };
  let queueItem_1: avSession.AVQueueItem = {
    itemId: 1,
    description: queueItemDescription_1
  };
  let queueItemDescription_2: avSession.AVMediaDescription = {
    assetId: '002',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    mediaImage: imagePixel,
    extras: {extras:'any'}
  };
  let queueItem_2: avSession.AVQueueItem = {
    itemId: 2,
    description: queueItemDescription_2
  };
  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
  currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
    console.info('SetAVQueueItems successfully');
  }).catch((err: BusinessError) => {
    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

setAVQueueItems10+

setAVQueueItems(items: Array<AVQueueItem>, callback: AsyncCallback<void>): void

设置媒体播放列表。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
items Array<AVQueueItem> 播放列表单项的队列,用以表示播放列表。
callback AsyncCallback<void> 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { image } from '@kit.ImageKit';
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

async function setAVQueueItems() {
  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
  let imageSource = await image.createImageSource(value.buffer);
  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
  let queueItemDescription_1: avSession.AVMediaDescription = {
    assetId: '001',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    mediaImage : imagePixel,
    extras: {extras:'any'}
  };
  let queueItem_1: avSession.AVQueueItem = {
    itemId: 1,
    description: queueItemDescription_1
  };
  let queueItemDescription_2: avSession.AVMediaDescription = {
    assetId: '002',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    mediaImage: imagePixel,
    extras: {extras:'any'}
  };
  let queueItem_2: avSession.AVQueueItem = {
    itemId: 2,
    description: queueItemDescription_2
  };
  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
  currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
    if (err) {
      console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
      console.info('SetAVQueueItems successfully');
    }
  });
}

setAVQueueTitle10+

setAVQueueTitle(title: string): Promise<void>

设置媒体播放列表名称。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
title string 播放列表的名称。

返回值:

类型 说明
Promise<void> Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle).then(() => {
  console.info('SetAVQueueTitle successfully');
}).catch((err: BusinessError) => {
  console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
});

setAVQueueTitle10+

setAVQueueTitle(title: string, callback: AsyncCallback<void>): void

设置媒体播放列表名称。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
title string 播放列表名称字段。
callback AsyncCallback<void> 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
  if (err) {
    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SetAVQueueTitle successfully');
  }
});

setExtras10+

setExtras(extras: {[key: string]: Object}): Promise<void>

媒体提供方设置键值对形式的自定义媒体数据包, 结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
extras {[key: string]: Object} 需要传递的自定义媒体数据包键值对。

说明:

参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

返回值:

类型 说明
Promise<void> Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => {
    console.info('setExtras successfully');
  }).catch((err: BusinessError) => {
    console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
  })
}

setExtras10+

setExtras(extras: {[key: string]: Object}, callback: AsyncCallback<void>): void

媒体提供方设置键值对形式的自定义媒体数据包, 结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
extras {[key: string]: Object} 需要传递的自定义媒体数据包键值对。
callback AsyncCallback<void> 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。

说明:

参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => {
    if (err) {
      console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
    }
  })
}

getController10+

getController(): Promise<AVSessionController>

获取本会话对应的控制器。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<AVSessionController> Promise对象。返回会话控制器。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avsessionController: avSession.AVSessionController;
currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
  avsessionController = avcontroller;
  console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
}).catch((err: BusinessError) => {
  console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
});

getController10+

getController(callback: AsyncCallback<AVSessionController>): void

获取本会话相应的控制器。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVSessionController> 回调函数。返回会话控制器。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avsessionController: avSession.AVSessionController;
currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
  if (err) {
    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    avsessionController = avcontroller;
    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
  }
});

getAVCastController10+

getAVCastController(): Promise<AVCastController>

设备建立连接后,获取投播控制器。结果通过Promise异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<AVCastController> Promise对象。返回投播控制器实例。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600102 The session does not exist.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let aVCastController: avSession.AVCastController;
currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
  aVCastController = avcontroller;
  console.info('getAVCastController : SUCCESS');
}).catch((err: BusinessError) => {
  console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVCastController10+

getAVCastController(callback: AsyncCallback<AVCastController>): void

设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVCastController> 回调函数,返回投播控制器实例。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600102 The session does not exist.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let aVCastController: avSession.AVCastController;
currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
  if (err) {
    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    aVCastController = avcontroller;
    console.info('getAVCastController : SUCCESS');
  }
});

getOutputDevice10+

getOutputDevice(): Promise<OutputDeviceInfo>

通过会话获取播放设备信息。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<OutputDeviceInfo> Promise对象。返回播放设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
  console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
}).catch((err: BusinessError) => {
  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
})

getOutputDevice10+

getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void

通过会话获取播放设备相关信息。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<OutputDeviceInfo> 回调函数,返回播放设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
  if (err) {
    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
  }
});

activate10+

activate(): Promise<void>

激活会话,激活后可正常使用会话。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<void> Promise对象。当会话激活成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.activate().then(() => {
  console.info('Activate : SUCCESS ');
}).catch((err: BusinessError) => {
  console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
});

activate10+

activate(callback: AsyncCallback<void>): void

激活会话,激活后可正常使用会话。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当会话激活成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.activate((err: BusinessError) => {
  if (err) {
    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('Activate : SUCCESS ');
  }
});

deactivate10+

deactivate(): Promise<void>

禁用当前会话的功能,可通过activate恢复。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<void> Promise对象。当禁用会话成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.deactivate().then(() => {
  console.info('Deactivate : SUCCESS ');
}).catch((err: BusinessError) => {
  console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
});

deactivate10+

deactivate(callback: AsyncCallback<void>): void

禁用当前会话。结果通过callback异步回调方式返回。

禁用当前会话的功能,可通过activate恢复。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当禁用会话成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.deactivate((err: BusinessError) => {
  if (err) {
    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('Deactivate : SUCCESS ');
  }
});

destroy10+

destroy(): Promise<void>

销毁当前会话,使当前会话完全失效。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<void> Promise对象。当会话销毁成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.destroy().then(() => {
  console.info('Destroy : SUCCESS ');
}).catch((err: BusinessError) => {
  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
});

destroy10+

destroy(callback: AsyncCallback<void>): void

销毁当前会话,使当前会话完全失效。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当会话销毁成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.destroy((err: BusinessError) => {
  if (err) {
    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('Destroy : SUCCESS ');
  }
});

on('play')10+

on(type: 'play', callback: () => void): void

设置播放命令监听事件。注册该监听,说明应用支持播放指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件为'play',当播放命令被发送到会话时,触发该事件回调。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('play', () => {
  console.info('on play entry');
});

on('pause')10+

on(type: 'pause', callback: () => void): void

设置暂停命令监听事件。注册该监听,说明应用支持暂停指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件为'pause',当暂停命令被发送到会话时,触发该事件回调。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('pause', () => {
  console.info('on pause entry');
});

on('stop')10+

on(type:'stop', callback: () => void): void

设置停止命令监听事件。注册该监听,说明应用支持停止指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是'stop',当停止命令被发送到会话时,触发该事件回调。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('stop', () => {
  console.info('on stop entry');
});

on('playNext')10+

on(type:'playNext', callback: () => void): void

设置播放下一首命令监听事件。注册该监听,说明应用支持下一首指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是'playNext',当播放下一首命令被发送到会话时,触发该事件回调。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('playNext', () => {
  console.info('on playNext entry');
});

on('playPrevious')10+

on(type:'playPrevious', callback: () => void): void

设置播放上一首命令监听事件。注册该监听,说明应用支持上一首指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是'playPrevious',当播放上一首命令被发送到会话时,触发该事件回调。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('playPrevious', () => {
  console.info('on playPrevious entry');
});

on('fastForward')10+

on(type: 'fastForward', callback: (time?: number) => void): void

设置快进命令监听事件。注册该监听,说明应用支持快进指令。

每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是 'fastForward',当快进命令被发送到会话时,触发该事件回调。
callback (time?: number) => void 回调函数。参数time是时间节点,单位为秒。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('fastForward', (time?: number) => {
  console.info('on fastForward entry');
});

on('rewind')10+

on(type:'rewind', callback: (time?: number) => void): void

设置快退命令监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是'rewind',当快退命令被发送到会话时,触发该事件回调。
callback (time?: number) => void 回调函数。参数time是时间节点,单位为秒。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('rewind', (time?: number) => {
  console.info('on rewind entry');
});

on('playFromAssetId')11+

on(type:'playFromAssetId', callback: (assetId: number) => void): void

设置媒体id播放监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持的事件是'playFromAssetId',当媒体id播放时,触发该事件回调。
callback callback: (assetId: number) => void 回调函数。参数assetId是媒体id。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('playFromAssetId', (assetId: number) => {
  console.info('on playFromAssetId entry');
});

off('playFromAssetId')11+

off(type: 'playFromAssetId', callback?: (assetId: number) => void): void

取消媒体id播放事件监听,关闭后,不再进行该事件回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'playFromAssetId'
callback callback: (assetId: number) => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。参数assetId是媒体id。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('playFromAssetId');

on('seek')10+

on(type: 'seek', callback: (time: number) => void): void

设置跳转节点监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'seek':当跳转节点命令被发送到会话时,触发该事件。
callback (time: number) => void 回调函数。参数time是时间节点,单位为毫秒。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('seek', (time: number) => {
  console.info(`on seek entry time : ${time}`);
});

on('setSpeed')10+

on(type: 'setSpeed', callback: (speed: number) => void): void

设置播放速率的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'setSpeed':当设置播放速率的命令被发送到会话时,触发该事件。
callback (speed: number) => void 回调函数。参数speed是播放倍速。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('setSpeed', (speed: number) => {
  console.info(`on setSpeed speed : ${speed}`);
});

on('setLoopMode')10+

on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void

设置循环模式的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'setLoopMode':当设置循环模式的命令被发送到会话时,触发该事件。
callback (mode: LoopMode) => void 回调函数。参数mode是循环模式。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
  console.info(`on setLoopMode mode : ${mode}`);
});

on('toggleFavorite')10+

on(type: 'toggleFavorite', callback: (assetId: string) => void): void

设置是否收藏的监听事件

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'toggleFavorite':当是否收藏的命令被发送到会话时,触发该事件。
callback (assetId: string) => void 回调函数。参数assetId是媒体ID。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('toggleFavorite', (assetId: string) => {
  console.info(`on toggleFavorite mode : ${assetId}`);
});

on('skipToQueueItem')10+

on(type: 'skipToQueueItem', callback: (itemId: number) => void): void

设置播放列表其中某项被选中的监听事件,session端可以选择对这个单项歌曲进行播放。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'skipToQueueItem':当播放列表选中单项的命令被发送到会话时,触发该事件。
callback (itemId: number) => void 回调函数。参数itemId是选中的播放列表项的ID。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('skipToQueueItem', (itemId: number) => {
  console.info(`on skipToQueueItem id : ${itemId}`);
});

on('handleKeyEvent')10+

on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void

设置蓝牙/有线等外设接入的按键输入事件的监听,监听多媒体按键事件中播放、暂停、上下一首、快进、快退的指令。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'handleKeyEvent':当按键事件被发送到会话时,触发该事件。
callback (event: KeyEvent) => void 回调函数。参数event是按键事件。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { KeyEvent } from '@kit.InputKit';

currentAVSession.on('handleKeyEvent', (event: KeyEvent) => {
  console.info(`on handleKeyEvent event : ${event}`);
});

on('outputDeviceChange')10+

on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void

设置播放设备变化的监听事件。应用接入系统投播组件,当用户通过组件切换设备时,会收到设备切换的回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'outputDeviceChange':当播放设备变化时,触发该事件。
callback (state: ConnectionState, device: OutputDeviceInfo) => void 回调函数,参数device是设备相关信息。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
  console.info(`on outputDeviceChange device : ${device}`);
});

on('commonCommand')10+

on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void

设置自定义控制命令变化的监听器。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'commonCommand':当自定义控制命令变化时,触发该事件。
callback (command: string, args: {[key:string]: Object}) => void 回调函数,command为变化的自定义控制命令名,args为自定义控制命令的参数,参数内容与sendCommonCommand方法设置的参数内容完全一致。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => {
    console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
  });
}

off('play')10+

off(type: 'play', callback?: () => void): void

取消会话播放事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'play'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('play');

off('pause')10+

off(type: 'pause', callback?: () => void): void

取消会话暂停事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'pause'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('pause');

off('stop')10+

off(type: 'stop', callback?: () => void): void

取消会话停止事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'stop'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('stop');

off('playNext')10+

off(type: 'playNext', callback?: () => void): void

取消会话播放下一首事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是 'playNext'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('playNext');

off('playPrevious')10+

off(type: 'playPrevious', callback?: () => void): void

取消会话播放上一首事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'playPrevious'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('playPrevious');

off('fastForward')10+

off(type: 'fastForward', callback?: () => void): void

取消会话快进事件监听,关闭后,不再进行该事件回调。

取消回调时,需要更新支持的命令列表。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'fastForward'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('fastForward');

off('rewind')10+

off(type: 'rewind', callback?: () => void): void

取消会话快退事件监听,关闭后,不再进行该事件回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'rewind'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('rewind');

off('seek')10+

off(type: 'seek', callback?: (time: number) => void): void

取消监听跳转节点事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'seek'
callback (time: number) => void 回调函数,参数time是时间节点,单位为毫秒。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('seek');

off('setSpeed')10+

off(type: 'setSpeed', callback?: (speed: number) => void): void

取消监听播放速率变化事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'setSpeed'
callback (speed: number) => void 回调函数,参数speed是播放倍速。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('setSpeed');

off('setLoopMode')10+

off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void

取消监听循环模式变化事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'setLoopMode'
callback (mode: LoopMode) => void 回调函数,参数mode是循环模式。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('setLoopMode');

off('toggleFavorite')10+

off(type: 'toggleFavorite', callback?: (assetId: string) => void): void

取消监听是否收藏的事件

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'toggleFavorite'
callback (assetId: string) => void 回调函数,参数assetId是媒体ID。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('toggleFavorite');

off('skipToQueueItem')10+

off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void

取消监听播放列表单项选中的事件

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'skipToQueueItem'
callback (itemId: number) => void 回调函数,参数itemId是播放列表单项ID。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('skipToQueueItem');

off('handleKeyEvent')10+

off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void

取消监听按键事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'handleKeyEvent'
callback (event: KeyEvent) => void 回调函数,参数event是按键事件。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('handleKeyEvent');

off('outputDeviceChange')10+

off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void

取消监听播放设备变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持关闭事件'outputDeviceChange'
callback (state: ConnectionState, device: OutputDeviceInfo) => void 回调函数,参数device是设备相关信息。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('outputDeviceChange');

off('commonCommand')10+

off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void

取消监听自定义控制命令的变化。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'commonCommand'
callback (command: string, args: {[key:string]: Object}) => void 回调函数,参数command是变化的自定义控制命令名,args为自定义控制命令的参数。
该参数为可选参数,若不填写该参数,则认为取消所有对command事件的监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('commonCommand');

on('answer')11+

on(type: 'answer', callback: Callback<void>): void;

设置通话接听的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'answer':当通话接听时,触发该事件。
callback Callback<void> 回调函数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('answer', () => {
  console.info('on call answer');
});

off('answer')11+

off(type: 'answer', callback?: Callback<void>): void;

取消通话接听事件的监听。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'answer'
callback Callback<void> 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('answer');

on('hangUp')11+

on(type: 'hangUp', callback: Callback<void>): void;

设置通话挂断的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'hangUp':当通话挂断时,触发该事件。
callback Callback<void> 回调函数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('hangUp', () => {
  console.info('on call hangUp');
});

off('hangUp')11+

off(type: 'hangUp', callback?: Callback<void>): void;

取消通话挂断事件的监听。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'hangUp'
callback Callback<void> 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('hangUp');

on('toggleCallMute')11+

on(type: 'toggleCallMute', callback: Callback<void>): void;

设置通话静音的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'toggleCallMute':当通话静音或解除静音时,触发该事件。
callback Callback<void> 回调函数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.on('toggleCallMute', () => {
  console.info('on call toggleCallMute');
});

off('toggleCallMute')11+

off(type: 'toggleCallMute', callback?: Callback<void>): void;

取消通话静音事件的监听。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'toggleCallMute'
callback Callback<void> 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('toggleCallMute');

on('castDisplayChange')12+

on(type: 'castDisplayChange', callback: Callback<CastDisplayInfo>): void

设置扩展屏投播显示设备变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'castDisplayChange':当扩展屏投播显示设备变化时触发事件。
callback Callback<CastDisplayInfo> 回调函数。参数是扩展屏投播显示设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

let castDisplay: avSession.CastDisplayInfo;
currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => {
    if (display.state === avSession.CastDisplayState.STATE_ON) {
        castDisplay = display;
        console.info(`Succeeded in castDisplayChange display : ${display.id} ON`);
    } else if (display.state === avSession.CastDisplayState.STATE_OFF){
        console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`);
    }
});

off('castDisplayChange')12+

off(type: 'castDisplayChange', callback?: Callback<CastDisplayInfo>): void

取消扩展屏投播显示设备变化事件监听,关闭后,不再进行该事件回调。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast

参数:

参数名 类型 必填 说明
type string 关闭对应的监听事件,支持的事件是'castDisplayChange'
callback Callback<CastDisplayInfo> 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600102 The session does not exist.

示例:

currentAVSession.off('castDisplayChange');

stopCasting10+

stopCasting(callback: AsyncCallback<void>): void

结束投播。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.stopCasting((err: BusinessError) => {
  if (err) {
    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('stopCasting successfully');
  }
});

stopCasting10+

stopCasting(): Promise<void>

结束投播。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<void> Promise对象。当成功结束投播,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

currentAVSession.stopCasting().then(() => {
  console.info('stopCasting successfully');
}).catch((err: BusinessError) => {
  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
});

getOutputDeviceSync10+

getOutputDeviceSync(): OutputDeviceInfo

使用同步方法获取当前输出设备信息。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
OutputDeviceInfo 当前输出设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
}

getAllCastDisplays12+

getAllCastDisplays(): Promise<Array<CastDisplayInfo>>

获取当前系统中所有支持扩展屏投播的显示设备。通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast

返回值:

类型 说明
Promise<Array<CastDisplayInfo>> Promise对象,返回当前系统中所有支持扩展屏投播的显示设备。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let castDisplay: avSession.CastDisplayInfo;
currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => {
    if (data.length >= 1) {
       castDisplay = data[0];
     }
   }).catch((err: BusinessError) => {
     console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`);
   });

AVCastControlCommandType10+

type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'

投播控制器可传递的命令。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

类型 说明
'play' 播放。
'pause' 暂停。
'stop' 停止。
'playNext' 下一首。
'playPrevious' 上一首。
'fastForward' 快进。
'rewind' 快退。
'seek' 跳转某一节点。
'setVolume' 设置音量。
'setSpeed' 设置播放倍速。
'setLoopMode' 设置循环模式。
'toggleFavorite' 是否收藏。
'toggleMute' 设置静音状态。

AVCastControlCommand10+

投播控制器接受的命令的对象描述。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 类型 必填 说明
command AVCastControlCommandType 命令。
parameter media.PlaybackSpeed | number | string | LoopMode 命令对应的参数。

AVCastController10+

在投播建立后,调用avSession.getAVCastController后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。

getAVPlaybackState10+

getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void

获取当前的远端播放状态。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVPlaybackState> 回调函数,返回远端播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
  if (err) {
    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('getAVPlaybackState : SUCCESS');
  }
});

getAVPlaybackState10+

getAVPlaybackState(): Promise<AVPlaybackState>

获取当前的远端播放状态。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<AVPlaybackState> Promise对象。返回远端播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
  console.info('getAVPlaybackState : SUCCESS');
}).catch((err: BusinessError) => {
  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
});

getSupportedDecoders18+

getSupportedDecoders(): Promise<Array<DecoderType>>

获取当前远端设备的编码方式。使用Promise异步回调。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<Array<DecoderType>> Promise对象。返回远端设备所支持的编码能力列表。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => {
  console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`);
  if (descriptors.length > 0 ) {
    console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`);
  }
}).catch((err: BusinessError) => {
  console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`);
});

getRecommendedResolutionLevel18+

getRecommendedResolutionLevel(decoderType: DecoderType): Promise<ResolutionLevel>

通过传递编码方式,获取推荐的分辨率。使用Promise异步回调。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<ResolutionLevel> Promise对象。返回远端设备推荐的分辨率。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC;
let resolutionLeve = avSession.ResolutionLevel;
aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLeve) => {
  console.info('getRecommendedResolutionLevel successfully');
}).catch((err: BusinessError) => {
  console.error(`getRecommendedResolutionLevel BusinessError: code: ${err.code}, message: ${err.message}`);
});

getSupportedHdrCapabilities18+

getSupportedHdrCapabilities(): Promise<Array<hdrCapability.HDRFormat>>

获取当前的远端设备所支持的HDR能力。使用Promise异步回调。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<Array<hdrCapability.HDRFormat>> Promise对象。返回远端设备所支持的HDR能力。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';
import type hdrCapability from './@ohos.graphics.hdrCapability';

aVCastController.getSupportedHdrCapabilities().then((hdrFormats: hdrCapability.HDRFormat[]) => {
  console.info(`getSupportedHdrCapabilities : SUCCESS : hdrFormats.length : ${hdrFormats.length}`);
  if (hdrFormats.length > 0 ) {
    console.info(`getSupportedHdrCapabilities : SUCCESS : descriptors[0] : ${hdrFormats[0]}`);
  }
}).catch((err: BusinessError) => {
  console.error(`getSupportedHdrCapabilities BusinessError: code: ${err.code}, message: ${err.message}`);
});

getSupportedPlaySpeeds18+

getSupportedPlaySpeeds(): Promise<Array<number>>

获取当前的远端设备所支持倍速播放列表。使用Promise异步回调。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<Array<number>> Promise对象。返回远端设备所支持的倍速播放列表。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getSupportedPlaySpeeds().then((nums: number[]) => {
  console.info(`getSupportedPlaySpeeds : SUCCESS : hdrFormats.length : ${nums.length}`);
  if (nums.length > 0 ) {
    console.info(`getSupportedPlaySpeeds : SUCCESS : descriptors[0] : ${nums[0]}`);
  }
}).catch((err: BusinessError) => {
  console.error(`getSupportedPlaySpeeds BusinessError: code: ${err.code}, message: ${err.message}`);
});

sendControlCommand10+

sendControlCommand(command: AVCastControlCommand): Promise<void>

通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
command AVCastControlCommand 会话的相关命令和命令相关参数。

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600105 Invalid session command.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avCommand: avSession.AVCastControlCommand = {command:'play'};
aVCastController.sendControlCommand(avCommand).then(() => {
  console.info('SendControlCommand successfully');
}).catch((err: BusinessError) => {
  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
});

sendControlCommand10+

sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback<void>): void

通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
command AVCastControlCommand 会话的相关命令和命令相关参数。
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600105 Invalid session command.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avCommand: avSession.AVCastControlCommand = {command:'play'};
aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
  if (err) {
    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SendControlCommand successfully');
  }
});

prepare10+

prepare(item: AVQueueItem, callback: AsyncCallback<void>): void

准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
item AVQueueItem 播放列表中单项的相关属性。
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

// 设置播放参数,开始播放。
let playItem: avSession.AVQueueItem = {
  itemId: 0,
  description: {
    assetId: '12345',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    appName: 'MyMusic'
  }
};
// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
aVCastController.prepare(playItem, (err: BusinessError) => {
  if (err) {
    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('prepare successfully');
  }
});

prepare10+

prepare(item: AVQueueItem): Promise<void>

准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
item AVQueueItem 播放列表中单项的相关属性。

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

// 设置播放参数,开始播放。
let playItem: avSession.AVQueueItem = {
  itemId: 0,
  description: {
    assetId: '12345',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    appName: 'MyMusic'
  }
};
// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
aVCastController.prepare(playItem).then(() => {
  console.info('prepare successfully');
}).catch((err: BusinessError) => {
  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
});

start10+

start(item: AVQueueItem, callback: AsyncCallback<void>): void

启动播放某个媒体资源。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
item AVQueueItem 播放列表中单项的相关属性。
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

// 设置播放参数,开始播放。
let playItem: avSession.AVQueueItem = {
  itemId: 0,
  description: {
    assetId: '12345',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    appName: 'MyMusic'
  }
};

// 启动播放。
aVCastController.start(playItem, (err: BusinessError) => {
  if (err) {
    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('start successfully');
  }
});

start10+

start(item: AVQueueItem): Promise<void>

启动播放某个媒体资源。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
item AVQueueItem 播放列表中单项的相关属性。

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600109 The remote connection is not established.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

// 设置播放参数,开始播放。
let playItem: avSession.AVQueueItem = {
  itemId: 0,
  description: {
    assetId: '12345',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    appName: 'MyMusic'
  }
};
// 启动播放。
aVCastController.start(playItem).then(() => {
  console.info('start successfully');
}).catch((err: BusinessError) => {
  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
});

getCurrentItem10+

getCurrentItem(callback: AsyncCallback<AVQueueItem>): void

获取当前投播的资源信息。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVQueueItem> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
  if (err) {
    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('getCurrentItem successfully');
  }
});

getCurrentItem10+

getCurrentItem(): Promise<AVQueueItem>

获取当前投播的资源信息。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<AVQueueItem> Promise对象,返回当前的播放资源,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
  console.info('getCurrentItem successfully');
}).catch((err: BusinessError) => {
  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
});

getValidCommands11+

getValidCommands(callback: AsyncCallback<Array<AVCastControlCommandType>>): void

获取当前支持的命令。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback Array<AVCastControlCommandType> 回调函数。返回当前支持的命令。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => {
  if (err) {
    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('getValidCommands successfully');
  }
});

getValidCommands11+

getValidCommands(): Promise<Array<AVCastControlCommandType>>

获取当前支持的命令。结果通过Promise异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<Array<AVCastControlCommandType>> Promise对象,返回当前支持的命令。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => {
  console.info('getValidCommands successfully');
}).catch((err: BusinessError) => {
  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
});

processMediaKeyResponse12+

processMediaKeyResponse(assetId: string, response: Uint8Array): Promise<void>

在线DRM资源投播时,处理许可证响应。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
assetId string 媒体ID。
response Uint8Array 许可证响应。

返回值:

类型 说明
Promise<void> Promise对象,当处理许可证响应成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.

示例:

let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
  // 根据assetId获取对应的DRM url。
  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
  // 从服务器获取许可证,需要开发者根据实际情况进行赋值。
  let licenseResponseData: Uint8Array = new Uint8Array();
  console.info(`Succeeded in get license by ${drmUrl}.`);
  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
}

release11+

release(callback: AsyncCallback<void>): void

销毁当前controller,结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当命令执行成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.release((err: BusinessError) => {
  if (err) {
    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('release successfully');
  }
});

release11+

release(): Promise<void>

销毁当前controller。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

返回值:

类型 说明
Promise<void> Promise对象,controller销毁成功,无结果返回,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.release().then(() => {
  console.info('release successfully');
}).catch((err: BusinessError) => {
  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
});

on('playbackStateChange')10+

on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void

设置播放状态变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'playbackStateChange':当播放状态变化时,触发该事件。
filter Array<keyof AVPlaybackState> | 'all' 'all' 表示关注播放状态所有字段变化;Array<keyof AVPlaybackState> 表示关注Array中的字段变化。
callback (state: AVPlaybackState) => void 回调函数,参数state是变化后的播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
  console.info(`on playbackStateChange state : ${playbackState.state}`);
});

let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
  console.info(`on playbackStateChange state : ${playbackState.state}`);
});

off('playbackStateChange')10+

off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void

媒体控制器取消监听播放状态变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'playbackStateChange'
callback (state: AVPlaybackState) => void 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('playbackStateChange');

on('mediaItemChange')10+

on(type: 'mediaItemChange', callback: Callback<AVQueueItem>): void

设置投播当前播放媒体内容的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'mediaItemChange':当播放的媒体内容变化时,触发该事件。
callback (callback: AVQueueItem) => void 回调函数,参数AVQueueItem是当前正在播放的媒体内容。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
  console.info(`on mediaItemChange state : ${item.itemId}`);
});

off('mediaItemChange')10+

off(type: 'mediaItemChange'): void

取消设置投播当前播放媒体内容的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'mediaItemChange'

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('mediaItemChange');

on('playNext')10+

on(type: 'playNext', callback: Callback<void>): void

设置播放下一首资源的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'playNext':当播放下一首状态变化时,触发该事件。
callback Callback<void> 回调函数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('playNext', () => {
  console.info('on playNext');
});

off('playNext')10+

off(type: 'playNext'): void

取消设置播放下一首资源的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'playNext'

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('playNext');

on('playPrevious')10+

on(type: 'playPrevious', callback: Callback<void>): void

设置播放上一首资源的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'playPrevious':当播放上一首状态变化时,触发该事件。
callback Callback<void> 回调函数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('playPrevious', () => {
  console.info('on playPrevious');
});

off('playPrevious')10+

off(type: 'playPrevious'): void

取消设置播放上一首资源的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'playPrevious'

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('playPrevious');

on('requestPlay')11+

on(type: 'requestPlay', callback: Callback<AVQueueItem>): void

设置请求播放的监听事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'requestPlay':当请求播放状态变化时,触发该事件。
callback (state: AVQueueItem) => void 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件注册成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
  console.info(`on requestPlay state : ${item.itemId}`);
});

off('requestPlay')11+

off(type: 'requestPlay', callback?: Callback<AVQueueItem>): void

取消设置请求播放的监听事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'requestPlay'
callback (state: AVQueueItem) => void 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('requestPlay');

on('endOfStream')11+

on(type: 'endOfStream', callback: Callback<void>): void

设置播放结束的监听事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'endOfStream':当资源播放结束时,触发该事件。
callback Callback<void> 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('endOfStream', () => {
  console.info('on endOfStream');
});

off('endOfStream')11+

off(type: 'endOfStream', callback?: Callback<void>): void

取消设置播放结束的监听事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'endOfStream'
callback Callback<void> 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('endOfStream');

on('seekDone')10+

on(type: 'seekDone', callback: Callback<number>): void

设置seek结束的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'seekDone':当seek结束时,触发该事件。
callback Callback<number> 回调函数,返回seek后播放的位置。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.on('seekDone', (pos: number) => {
  console.info(`on seekDone pos:${pos} `);
});

off('seekDone')10+

off(type: 'seekDone'): void

取消设置seek结束的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'seekDone'

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('seekDone');

on('validCommandChange')11+

on(type: 'validCommandChange', callback: Callback<Array<AVCastControlCommandType>>)

会话支持的有效命令变化监听事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'validCommandChange':当检测到会话的合法命令发生改变时,触发该事件。
callback Callback<Array<AVCastControlCommandType>> 回调函数。参数commands是有效命令的集合。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
});

off('validCommandChange')11+

off(type: 'validCommandChange', callback?: Callback<Array<AVCastControlCommandType>>)

媒体控制器取消监听会话有效命令变化的事件。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'validCommandChange'
callback Callback<Array<AVCastControlCommandType>> 回调函数。参数commands是有效命令的集合。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

aVCastController.off('validCommandChange');

on('error')10+

on(type: 'error', callback: ErrorCallback): void

监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。
callback ErrorCallback 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。

错误码:

以下错误码的详细介绍请参见媒体服务错误码以及媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
5400101 No memory.
5400102 Operation not allowed.
5400103 I/O error.
5400104 Time out.
5400105 Service died.
5400106 Unsupport format.
6600101 Session service exception.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

aVCastController.on('error', (error: BusinessError) => {
  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('error')10+

off(type: 'error'): void

取消监听播放的错误事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,取消注册的事件:'error'。

错误码:

以下错误码的详细介绍请参见媒体服务错误码以及媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
5400101 No memory.
5400102 Operation not allowed.
5400103 I/O error.
5400104 Time out.
5400105 Service died.
5400106 Unsupport format.
6600101 Session service exception.

示例:

aVCastController.off('error')

on('keyRequest')12+

on(type: 'keyRequest', callback: KeyRequestCallback): void

在线DRM资源投播时,设置许可证请求的事件监听。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'keyRequest':当DRM资源播放需要许可证时,触发该事件。
callback KeyRequestCallback 回调函数,媒体资源及许可证请求数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
}
aVCastController.on('keyRequest', keyRequestCallback);

off('keyRequest')12+

off(type: 'keyRequest', callback?: KeyRequestCallback): void

取消监听许可证请求的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'keyRequest'
callback KeyRequestCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.

示例:

aVCastController.off('keyRequest');

on('castControlGenericError')13+

on(type: 'castControlGenericError', callback: ErrorCallback): void

监听投播通用错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlGenericError'。
callback ErrorCallback 投播通用错误事件回调方法。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6611000 The error code for cast control is unspecified.
6611001 An unspecified error occurs in the remote player.
6611002 The playback position falls behind the live window.
6611003 The process of cast control times out.
6611004 The runtime check failed.
6611100 Cross-device data transmission is locked.
6611101 The specified seek mode is not supported.
6611102 The position to seek to is out of the range of the media asset or the specified seek mode is not supported.
6611103 The specified playback mode is not supported.
6611104 The specified playback speed is not supported.
6611105 The action failed because either the media source device or the media sink device has been revoked.
6611106 The parameter is invalid, for example, the url is illegal to play.
6611107 Allocation of memory failed.
6611108 Operation is not allowed.

示例:

aVCastController.on('castControlGenericError', (error: BusinessError) => {
  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlGenericError')13+

off(type: 'castControlGenericError', callback?: ErrorCallback): void

取消监听投播通用的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlGenericError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlGenericError');

on('castControlIoError')13+

on(type: 'castControlIoError', callback: ErrorCallback): void

监听投播输入/输出的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlIoError'。
callback ErrorCallback 投播输入/输出的错误事件回调方法。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6612000 An unspecified input/output error occurs.
6612001 Network connection failure.
6612002 Network timeout.
6612003 Invalid "Content-Type" HTTP header.
6612004 The HTTP server returns an unexpected HTTP response status code.
6612005 The file does not exist.
6612006 No permission is granted to perform the IO operation.
6612007 Access to cleartext HTTP traffic is not allowed by the app's network security configuration.
6612008 Reading data out of the data bound.
6612100 The media does not contain any contents that can be played.
6612101 The media cannot be read, for example, because of dust or scratches.
6612102 This resource is already in use.
6612103 The content using the validity interval has expired.
6612104 Using the requested content to play is not allowed.
6612105 The use of the allowed content cannot be verified.
6612106 The number of times this content has been used as requested has reached the maximum allowed number of uses.
6612107 An error occurs when sending packet from source device to sink device.

示例:

aVCastController.on('castControlIoError', (error: BusinessError) => {
  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlIoError')13+

off(type: 'castControlIoError', callback?: ErrorCallback): void

取消监听投播输入/输出的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlIoError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlIoError');

on('castControlParsingError')13+

on(type: 'castControlParsingError', callback: ErrorCallback): void

监听投播解析的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlParsingError'。
callback ErrorCallback 投播解析的错误事件回调方法。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6613000 Unspecified error related to content parsing.
6613001 Parsing error associated with media container format bit streams.
6613002 Parsing error associated with the media manifest.
6613003 An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.
6613004 Unsupported feature in the media manifest.

示例:

aVCastController.on('castControlParsingError', (error: BusinessError) => {
  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlParsingError')13+

off(type: 'castControlParsingError', callback?: ErrorCallback): void

取消监听投播解析的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlParsingError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlParsingError');

on('castControlDecodingError')13+

on(type: 'castControlDecodingError', callback: ErrorCallback): void

监听投播解码的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlDecodingError'。
callback ErrorCallback 投播解码的错误事件回调方法。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6614000 Unspecified decoding error.
6614001 Decoder initialization failed.
6614002 Decoder query failed.
6614003 Decoding the media samples failed.
6614004 The format of the content to decode exceeds the capabilities of the device.
6614005 The format of the content to decode is not supported.

示例:

aVCastController.on('castControlDecodingError', (error: BusinessError) => {
  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlDecodingError')13+

off(type: 'castControlDecodingError', callback?: ErrorCallback): void

取消监听投播解码的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlDecodingError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlDecodingError');

on('castControlAudioRendererError')13+

on(type: 'castControlAudioRendererError', callback: ErrorCallback): void

监听投播音频渲染器的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlAudioRendererError'。
callback ErrorCallback 投播音频渲染器的错误事件回调方法。

错误码:

以下错误码的详细介绍请参见媒体服务错误码以及媒体会话管理错误码

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6615000 Unspecified errors related to the audio renderer.
6615001 Initializing the audio renderer failed.
6615002 The audio renderer fails to write data.

示例:

aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlAudioRendererError')13+

off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void

取消监听投播音频渲染器的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlAudioRendererError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlAudioRendererError');

on('castControlDrmError')13+

on(type: 'castControlDrmError', callback: ErrorCallback): void

监听投播drm的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 错误事件回调类型,支持的事件:'castControlDrmError'。
callback ErrorCallback 投播drm的错误事件回调方法。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
6616000 Unspecified error related to DRM.
6616001 The chosen DRM protection scheme is not supported by the device.
6616002 Device provisioning failed.
6616003 The DRM-protected content to play is incompatible.
6616004 Failed to obtain a license.
6616005 The operation is disallowed by the license policy.
6616006 An error occurs in the DRM system.
6616007 The device has revoked DRM privileges.
6616008 The DRM license being loaded into the open DRM session has expired.
6616100 An error occurs when the DRM processes the key response.

示例:

aVCastController.on('castControlDrmError', (error: BusinessError) => {
  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
})

off('castControlDrmError')13+

off(type: 'castControlDrmError', callback?: ErrorCallback): void

取消监听投播drm的错误事件。

原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持的事件是'castControlDrmError'。
callback ErrorCallback 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

错误码ID 错误信息
401 Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.

示例:

aVCastController.off('castControlDrmError');

ExtraInfo18+

type ExtraInfo = { [key: string]: Object; }

媒体提供方设置的自定义媒体数据包对象。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

类型 说明
[key: string]: Object key为远端分布式事件类型。当前支持的事件类型包括:
'AUDIO_GET_VOLUME':获取远端设备音量。
'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备。
'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。
媒体提供方根据不同的远端分布式事件类型,返回对应的媒体数据包Object对象。

KeyRequestCallback12+

type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void

许可证请求事件的回调函数。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
assetId string 媒体ID。
requestData Uint8Array 媒体许可证请求数据。

示例:

let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
}

CastDisplayState12+

投播显示设备状态的枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast

名称 说明
STATE_OFF 1 设备断开,扩展屏不再显示内容。
STATE_ON 2 设备连接成功,扩展屏可用。

CastDisplayInfo12+

扩展屏投播显示设备相关属性。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast

名称 类型 只读 可选 说明
id number 投播显示设备的ID,该参数应为整数。
name string 投播显示设备的名称。
state CastDisplayState 投播显示设备状态。
width number 投播显示设备的屏幕宽度,单位为px,该参数应为整数。
height number 投播显示设备的屏幕高度,单位为px,该参数应为整数。

ConnectionState10+

连接状态枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
STATE_CONNECTING 0 设备连接中。
STATE_CONNECTED 1 设备连接成功。
STATE_DISCONNECTED 6 设备断开连接。

AVMetadata10+

媒体元数据的相关属性。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 只读 可选 说明
assetId string 媒体ID。歌曲的唯一标识,由应用自定义。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
title string 标题。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
artist string 艺术家。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
author string 专辑作者。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
avQueueName12+ string 歌单(歌曲列表)名称。
avQueueId11+ string 歌单(歌曲列表)唯一标识Id。
avQueueImage11+ image.PixelMap | string 歌单(歌曲列表)封面图。
图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。
- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。
- 设置为url图片路径,获取的为url图片路径。
album string 专辑名称。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
writer string 词作者。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
composer string 作曲者。
duration number 媒体时长,单位毫秒(ms)。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
mediaImage image.PixelMap | string 图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。
- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。
- 设置为url图片路径,获取的为url图片路径。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
bundleIcon18+ image.PixelMap 应用图标图片的像素数据。只读类型,不从应用侧设置。
原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。
publishDate Date 发行日期。
subtitle string 子标题。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
description string 媒体描述。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
lyric string 媒体歌词内容。应用需将歌词内容拼接为一个字符串传入。
字符串长度需<=40960字节。
说明: 系统支持简单版的LRC格式(Simple LRC format)的歌词文本内容。当传入的歌词内容不规范(例如:出现重复的时间戳等),将导致解析失败,并在系统中显示异常。
singleLyricText18+ string 单条媒体歌词内容。应用需将歌词内容拼接为一个字符串传入(不包含时间戳)。
字符串长度<=40960字节。
原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。
previousAssetId string 上一首媒体ID。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
nextAssetId string 下一首媒体ID。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
filter11+ number 当前session支持的协议,默认为TYPE_CAST_PLUS_STREAM。具体取值参考ProtocolType
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
drmSchemes12+ Array<string> 当前session支持的DRM方案,取值为DRM方案uuid。
skipIntervals11+ SkipIntervals 快进快退支持的时间间隔。默认为SECONDS_15,即15秒。
displayTags11+ number 媒体资源的金标类型,取值参考DisplayTag

AVMediaDescription10+

播放列表媒体元数据的相关属性。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
assetId string 播放列表媒体ID。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
title string 播放列表媒体标题。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
subtitle string 播放列表媒体子标题。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
description string 播放列表媒体描述的文本。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
mediaImage image.PixelMap | string 播放列表媒体图片像素数据。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
extras {[key: string]: Object} 播放列表媒体额外字段。
mediaUri string 播放列表媒体URI。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
mediaType string 播放列表媒体类型。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
mediaSize number 播放列表媒体的大小。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
albumTitle string 播放列表媒体专辑标题。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
albumCoverUri string 播放列表媒体专辑标题URI。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
lyricContent string 播放列表媒体歌词内容。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
lyricUri string 播放列表媒体歌词URI。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
artist string 播放列表媒体专辑作者。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
fdSrc media.AVFileDescriptor 播放列表媒体本地文件的句柄。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
dataSrc12+ media.AVDataSrcDescriptor 播放列表数据源描述。
drmScheme12+ string 播放列表媒体支持的DRM方案,由uuid表示。
duration number 播放列表媒体播放时长。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
startPosition number 播放列表媒体起始播放位置。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
creditsPosition number 播放列表媒体的片尾播放位置。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
appName string 播放列表提供的应用的名字。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
displayTags11+ number 媒体资源的金标类型,取值参考DisplayTag
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

AVQueueItem10+

播放列表中单项的相关属性。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
itemId number 播放列表中单项的ID。
description AVMediaDescription 播放列表中单项的媒体元数据。

AVPlaybackState10+

媒体播放状态的相关属性。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
state PlaybackState 播放状态。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
speed number 播放倍速。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
position PlaybackPosition 播放位置。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
bufferedTime number 缓冲时间。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
loopMode LoopMode 循环模式。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
isFavorite boolean 是否收藏。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
activeItemId10+ number 正在播放的媒体Id。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
volume10+ number 正在播放的媒体音量。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
maxVolume11+ number 最大音量。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
muted11+ boolean 当前静音状态,true表示静音。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
duration11+ number 当前媒体资源的时长。
videoWidth11+ number 媒体资源的视频宽度,单位为像素(px)。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
videoHeight11+ number 媒体资源的视频高度,单位为像素(px)。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
extras10+ {[key: string]: Object} 自定义媒体数据。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

PlaybackPosition10+

媒体播放位置的相关属性。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
elapsedTime number 已用时间,单位毫秒(ms)。
updateTime number 更新时间,单位毫秒(ms)。

CallMetadata11+

通话会话元数据相关属性。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
name string 来电人姓名(别名)。
phoneNumber string 来电电话号码。
avatar image.PixelMap 来电人头像。

AVCallState11+

通话状态相关属性。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
state CallState 当前通话状态。
muted boolean 通话mic是否静音。
true:静音。
false:不是静音。

CallState11+

表示通话状态的枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
CALL_STATE_IDLE 0 空闲状态。
CALL_STATE_INCOMING 1 来电。
CALL_STATE_ACTIVE 2 接通。
CALL_STATE_DIALING 3 响铃。
CALL_STATE_WAITING 4 等待接通。
CALL_STATE_HOLDING 5 保持。
CALL_STATE_DISCONNECTING 6 挂断。

DisplayTag11+

枚举,表示当前媒体资源的金标,即应用媒体音源的特殊类型标识。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
TAG_AUDIO_VIVID 1 AUDIO VIVID

DecoderType18+

枚举,设备所支持的编码格式。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 说明
OH_AVCODEC_MIMETYPE_VIDEO_AVC "video/avc" VIDEO AVC
OH_AVCODEC_MIMETYPE_VIDEO_HEVC "video/hevc" VIDEO HEVC
OH_AVCODEC_MIMETYPE_AUDIO_VIVID "audio/av3a" AUDIO AV3A

ResolutionLevel18+

枚举,设备所支持的分辨率。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 说明
RESOLUTION_480P 0 分辨率为480P(640*480 dpi)。
RESOLUTION_720P 1 分辨率为720P(1280*720 dpi)。
RESOLUTION_1080P 2 分辨率为1080P(1920*1080 dpi)。
RESOLUTION_2K 3 分辨率为2k(2560*1440 dpi)。
RESOLUTION_4K 4 分辨率为4k(4096*3840 dpi)。

AVCastCategory10+

投播的类别枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 说明
CATEGORY_LOCAL 0 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。
CATEGORY_REMOTE 1 远端播放,远端播放设备,声音从其他设备发出声音或者画面。

DeviceType10+

播放设备的类型枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

名称 说明
DEVICE_TYPE_LOCAL 0 本地播放类型。
系统能力: SystemCapability.Multimedia.AVSession.Core
DEVICE_TYPE_BLUETOOTH 10 蓝牙设备。
系统能力: SystemCapability.Multimedia.AVSession.Core
DEVICE_TYPE_TV 2 电视。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
DEVICE_TYPE_SMART_SPEAKER 3 音箱设备。
系统能力: SystemCapability.Multimedia.AVSession.AVCast

DeviceInfo10+

播放设备的相关信息。

名称 类型 必填 说明
castCategory AVCastCategory 投播的类别。
系统能力: SystemCapability.Multimedia.AVSession.Core
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
deviceId string 播放设备的ID。
系统能力: SystemCapability.Multimedia.AVSession.Core
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
deviceName string 播放设备的名称。
系统能力: SystemCapability.Multimedia.AVSession.Core
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
deviceType DeviceType 播放设备的类型。
系统能力: SystemCapability.Multimedia.AVSession.Core
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
supportedProtocols11+ number 播放设备支持的协议。默认为TYPE_LOCAL。具体取值参考ProtocolType
系统能力: SystemCapability.Multimedia.AVSession.AVCast
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
supportedDrmCapabilities12+ Array<string> 播放设备支持的DRM能力。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
manufacturer13+ string 播放设备生产厂家。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
modelName13+ string 播放设备型号名称。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。

OutputDeviceInfo10+

播放设备的相关信息。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
devices Array<DeviceInfo> 播放设备的集合。

LoopMode10+

表示媒体播放循环模式的枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
LOOP_MODE_SEQUENCE 0 顺序播放。
LOOP_MODE_SINGLE 1 单曲循环。
LOOP_MODE_LIST 2 表单循环。
LOOP_MODE_SHUFFLE 3 随机播放。
LOOP_MODE_CUSTOM11+ 4 自定义播放。

PlaybackState10+

表示媒体播放状态的枚举。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
PLAYBACK_STATE_INITIAL 0 初始状态。
PLAYBACK_STATE_PREPARE 1 播放准备状态。
PLAYBACK_STATE_PLAY 2 正在播放。
PLAYBACK_STATE_PAUSE 3 暂停。
PLAYBACK_STATE_FAST_FORWARD 4 快进。
PLAYBACK_STATE_REWIND 5 快退。
PLAYBACK_STATE_STOP 6 停止。
PLAYBACK_STATE_COMPLETED 7 播放完成。
PLAYBACK_STATE_RELEASED 8 释放。
PLAYBACK_STATE_ERROR 9 错误。
PLAYBACK_STATE_IDLE11+ 10 空闲。
PLAYBACK_STATE_BUFFERING11+ 11 缓冲。

AVSessionController10+

AVSessionController控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。

属性

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 可读 可写 说明
sessionId string AVSessionController对象唯一的会话标识。

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let AVSessionController: avSession.AVSessionController;
avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
  AVSessionController = controller;
}).catch((err: BusinessError) => {
  console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVPlaybackState10+

getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void

获取当前的远端播放状态。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVPlaybackState> 回调函数,返回远端播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
  if (err) {
    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('getAVPlaybackState : SUCCESS');
  }
});

getAVPlaybackState10+

getAVPlaybackState(): Promise<AVPlaybackState>

获取当前的远端播放状态。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<AVPlaybackState> Promise对象。返回远端播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
  console.info('getAVPlaybackState : SUCCESS');
}).catch((err: BusinessError) => {
  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVMetadata10+

getAVMetadata(): Promise<AVMetadata>

获取会话元数据。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<AVMetadata> Promise对象,返回会话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
  console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
}).catch((err: BusinessError) => {
  console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVMetadata10+

getAVMetadata(callback: AsyncCallback<AVMetadata>): void

获取会话元数据。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVMetadata> 回调函数,返回会话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
  if (err) {
    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
  }
});

getAVQueueTitle10+

getAVQueueTitle(): Promise<string>

获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<string> Promise对象。返回播放列表名称。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVQueueTitle().then((title: string) => {
  console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
}).catch((err: BusinessError) => {
  console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVQueueTitle10+

getAVQueueTitle(callback: AsyncCallback<string>): void

获取当前播放列表的名称。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<string> 回调函数,返回播放列表名称。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
  if (err) {
    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
  }
});

getAVQueueItems10+

getAVQueueItems(): Promise<Array<AVQueueItem>>

获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<Array<AVQueueItem>> Promise对象。返回播放列表队列。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
  console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
}).catch((err: BusinessError) => {
  console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVQueueItems10+

getAVQueueItems(callback: AsyncCallback<Array<AVQueueItem>>): void

获取当前播放列表相关信息。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<AVQueueItem>> 回调函数,返回播放列表队列。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
  if (err) {
    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
  }
});

skipToQueueItem10+

skipToQueueItem(itemId: number): Promise<void>

设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
itemId number 播放列表单项的ID值,用以表示选中的播放列表单项。

返回值:

类型 说明
Promise<void> Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId).then(() => {
  console.info('SkipToQueueItem successfully');
}).catch((err: BusinessError) => {
  console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
});

skipToQueueItem10+

skipToQueueItem(itemId: number, callback: AsyncCallback<void>): void

设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
itemId number 播放列表单项的ID值,用以表示选中的播放列表单项。
callback AsyncCallback<void> 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
  if (err) {
    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SkipToQueueItem successfully');
  }
});

getOutputDevice10+

getOutputDevice(): Promise<OutputDeviceInfo>

获取播放设备信息。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<OutputDeviceInfo> Promise对象,返回播放设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
600101 Session service exception.
600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
  console.info('GetOutputDevice : SUCCESS');
}).catch((err: BusinessError) => {
  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
});

getOutputDevice10+

getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void

获取播放设备信息。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<OutputDeviceInfo> 回调函数,返回播放设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
600101 Session service exception.
600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
  if (err) {
    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('GetOutputDevice : SUCCESS');
  }
});

sendAVKeyEvent10+

sendAVKeyEvent(event: KeyEvent): Promise<void>

发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
event KeyEvent 按键事件。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
600101 Session service exception.
600102 The session does not exist.
600103 The session controller does not exist.
600105 Invalid session command.
600106 The session is not activated.

返回值:

类型 说明
Promise<void> Promise对象。当事件发送成功,无返回结果,否则返回错误对象。

示例:

import { Key, KeyEvent } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};


avsessionController.sendAVKeyEvent(event).then(() => {
  console.info('SendAVKeyEvent Successfully');
}).catch((err: BusinessError) => {
  console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
});

sendAVKeyEvent10+

sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void

发送按键事件到会话。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
event KeyEvent 按键事件。
callback AsyncCallback<void> 回调函数。当事件发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
600101 Session service exception.
600102 The session does not exist.
600103 The session controller does not exist.
600105 Invalid session command.
600106 The session is not activated.

示例:

import { Key, KeyEvent } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
avsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
  if (err) {
    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SendAVKeyEvent Successfully');
  }
});

getLaunchAbility10+

getLaunchAbility(): Promise<WantAgent>

获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<WantAgent> Promise对象,返回在setLaunchAbility保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getLaunchAbility().then((agent: object) => {
  console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
}).catch((err: BusinessError) => {
  console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
});

getLaunchAbility10+

getLaunchAbility(callback: AsyncCallback<WantAgent>): void

获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<WantAgent> 回调函数。返回在setLaunchAbility保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
  if (err) {
    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
  }
});

getRealPlaybackPositionSync10+

getRealPlaybackPositionSync(): number

获取当前播放位置。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
number 时间节点,毫秒数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

let time: number = avsessionController.getRealPlaybackPositionSync();

isActive10+

isActive(): Promise<boolean>

获取会话是否被激活。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<boolean> Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.isActive().then((isActive: boolean) => {
  console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
}).catch((err: BusinessError) => {
  console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
});

isActive10+

isActive(callback: AsyncCallback<boolean>): void

判断会话是否被激活。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回会话是否为激活状态,true表示被激活,false表示禁用。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.isActive((err: BusinessError, isActive: boolean) => {
  if (err) {
    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
  }
});

destroy10+

destroy(): Promise<void>

销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<void> Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.destroy().then(() => {
  console.info('Destroy : SUCCESS ');
}).catch((err: BusinessError) => {
  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
});

destroy10+

destroy(callback: AsyncCallback<void>): void

销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.destroy((err: BusinessError) => {
  if (err) {
    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('Destroy : SUCCESS ');
  }
});

getValidCommands10+

getValidCommands(): Promise<Array<AVControlCommandType>>

获取会话支持的有效命令。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<Array<AVControlCommandType>> Promise对象。返回有效命令的集合。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
  console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
}).catch((err: BusinessError) => {
  console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
});

getValidCommands10+

getValidCommands(callback: AsyncCallback<Array<AVControlCommandType>>): void

获取会话支持的有效命令。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<AVControlCommandType>> 回调函数,返回有效命令的集合。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
  if (err) {
    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
  }
});

sendControlCommand10+

sendControlCommand(command: AVControlCommand): Promise<void>

通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。

说明:

媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口on'play'on'pause'等。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
command AVControlCommand 会话的相关命令和命令相关参数。

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600106 The session is not activated.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avCommand: avSession.AVControlCommand = {command:'play'};
avsessionController.sendControlCommand(avCommand).then(() => {
  console.info('SendControlCommand successfully');
}).catch((err: BusinessError) => {
  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
});

sendControlCommand10+

sendControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void

通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。

说明:

媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口on'play'on'pause'等。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
command AVControlCommand 会话的相关命令和命令相关参数。
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600106 The session is not activated.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avCommand: avSession.AVControlCommand = {command:'play'};
avsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
  if (err) {
    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info('SendControlCommand successfully');
  }
});

sendCommonCommand10+

sendCommonCommand(command: string, args: {[key: string]: Object}): Promise<void>

通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
command string 需要设置的自定义控制命令的名称。
args {[key: string]: Object} 需要传递的控制命令键值对。

说明: 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600106 The session is not activated.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);
let sessionId: string = "";
avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  sessionId = (currentAVSession as avSession.AVSession).sessionId;
  avSession.createController(sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

let commandName = "my_command";
if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
    console.info('SendCommonCommand successfully');
  }).catch((err: BusinessError) => {
    console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
  })
}

sendCommonCommand10+

sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback<void>): void

通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
command string 需要设置的自定义控制命令的名称。
args {[key: string]: Object} 需要传递的控制命令键值对。
callback AsyncCallback<void> 回调函数。当命令发送成功,err为undefined,否则返回错误对象。

说明: 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600106 The session is not activated.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';
let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

let commandName = "my_command";
if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
    if (err) {
        console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
    }
  })
}

getExtras10+

getExtras(): Promise<{[key: string]: Object}>

获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<{[key: string]: Object}> Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).getExtras().then((extras) => {
    console.info(`getExtras : SUCCESS : ${extras}`);
  }).catch((err: BusinessError) => {
    console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

getExtras10+

getExtras(callback: AsyncCallback<{[key: string]: Object}>): void

获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<{[key: string]: Object}> 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.
6600107 Too many commands or events.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).getExtras((err, extras) => {
    if (err) {
      console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
      console.info(`getExtras : SUCCESS : ${extras}`);
    }
  });
}

getExtrasWithEvent18+

getExtrasWithEvent(extraEvent: string): Promise<ExtraInfo>

根据远端分布式事件类型,获取远端分布式媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。

原子化服务API: 从API version 18开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
extraEvent string 远端分布式事件类型。
当前支持的事件类型包括:
'AUDIO_GET_VOLUME':获取远端设备音量,
'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备,
'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。

返回值:

类型 说明
Promise<ExtraInfo> Promise对象,返回远端分布式媒体提供方设置的自定义媒体数据包。
参数ExtraInfo支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见@ohos.app.ability.Want(Want)

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed.
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.
6600105 Invalid session command.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  @State message: string = 'hello world';

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(40)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            getExtrasWithEventTest();
          })
      }
    }
  }
}

async function getExtrasWithEventTest() {
  let controllerList: Array<avSession.AVSessionController>;
  let controller: avSession.AVSessionController | ESObject;
  
  try {
    controllerList = await avSession.getDistributedSessionController(avSession.DistributedSessionType.TYPE_SESSION_REMOTE);
    controller = controllerList[0];
  } catch (err) {
    console.info(`getDistributedSessionController fail with err: ${err}`);
  }

  const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME';
  const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES';
  const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO';
  if (controller !== undefined) {
    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then((extras: avSession.ExtraInfo) => {
      console.info(`${extras[COMMON_COMMAND_STRING_1]}`);
    }).catch((err: BusinessError) => {
      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
    })

    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then((extras: avSession.ExtraInfo) => {
      console.info(`${extras[COMMON_COMMAND_STRING_2]}`);
    }).catch((err: BusinessError) => {
      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
    })

    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then((extras: avSession.ExtraInfo) => {
      console.info(`${extras[COMMON_COMMAND_STRING_3]}`);
    }).catch((err: BusinessError) => {
      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
    })
  }
}

on('metadataChange')10+

on(type: 'metadataChange', filter: Array<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)

设置元数据变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'metadataChange':当元数据变化时,触发该事件。
filter Array<keyof AVMetadata> | 'all' 'all' 表示关注元数据所有字段变化;Array<keyof AVMetadata> 表示关注Array中的字段变化。
callback (data: AVMetadata) => void 回调函数,参数data是变化后的元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
  console.info(`on metadataChange assetId : ${metadata.assetId}`);
});

avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
  console.info(`on metadataChange assetId : ${metadata.assetId}`);
});

off('metadataChange')10+

off(type: 'metadataChange', callback?: (data: AVMetadata) => void)

媒体控制器取消监听元数据变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'metadataChange'
callback (data: AVMetadata) => void 回调函数,参数data是变化后的元数据。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('metadataChange');

on('playbackStateChange')10+

on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)

设置播放状态变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'playbackStateChange':当播放状态变化时,触发该事件。
filter Array<keyof AVPlaybackState> | 'all' 'all' 表示关注播放状态所有字段变化;Array<keyof AVPlaybackState> 表示关注Array中的字段变化。
callback (state: AVPlaybackState) => void 回调函数,参数state是变化后的播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
  console.info(`on playbackStateChange state : ${playbackState.state}`);
});

avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
  console.info(`on playbackStateChange state : ${playbackState.state}`);
});

off('playbackStateChange')10+

off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)

媒体控制器取消监听播放状态变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'playbackStateChange'
callback (state: AVPlaybackState) => void 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('playbackStateChange');

on('callMetadataChange')11+

on(type: 'callMetadataChange', filter: Array<keyof CallMetadata> | 'all', callback: Callback<CallMetadata>): void;

设置通话元数据变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'callMetadataChange':当通话元数据变化时,触发该事件。
filter Array<keyof CallMetadata> | 'all' 'all' 表示关注通话元数据所有字段变化;Array<keyof CallMetadata> 表示关注Array中的字段变化。
callback Callback<CallMetadata>> 回调函数,参数callmetadata是变化后的通话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
  console.info(`on callMetadataChange state : ${callmetadata.name}`);
});

avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
  console.info(`on callMetadataChange state : ${callmetadata.name}`);
});

off('callMetadataChange')11+

off(type: 'callMetadataChange', callback?: Callback<CallMetadata>): void;

取消设置通话元数据变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'callMetadataChange'
callback Callback<CallMetadata> 回调函数,参数calldata是变化后的通话原数据。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('callMetadataChange');

on('callStateChange')11+

on(type: 'callStateChange', filter: Array<keyof AVCallState> | 'all', callback: Callback<AVCallState>): void;

设置通话状态变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'callStateChange':当通话状态变化时,触发该事件。
filter Array<keyof AVCallState> | 'all' 'all' 表示关注通话状态所有字段变化;Array<keyof AVCallState> 表示关注Array中的字段变化。
callback Callback<AVCallState> 回调函数,参数callstate是变化后的通话状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
  console.info(`on callStateChange state : ${callstate.state}`);
});

avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
  console.info(`on callStateChange state : ${callstate.state}`);
});

off('callStateChange')11+

off(type: 'callStateChange', callback?: Callback<AVCallState>): void;

取消设置通话状态变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'callStateChange'
callback Callback<AVCallState> 回调函数,参数callstate是变化后的通话状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('callMetadataChange');

on('sessionDestroy')10+

on(type: 'sessionDestroy', callback: () => void)

会话销毁的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'sessionDestroy':当检测到会话销毁时,触发该事件)。
callback () => void 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('sessionDestroy', () => {
  console.info('on sessionDestroy : SUCCESS ');
});

off('sessionDestroy')10+

off(type: 'sessionDestroy', callback?: () => void)

媒体控制器取消监听会话的销毁事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'sessionDestroy'
callback () => void 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('sessionDestroy');

on('activeStateChange')10+

on(type: 'activeStateChange', callback: (isActive: boolean) => void)

会话的激活状态的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'activeStateChange':当检测到会话的激活状态发生改变时,触发该事件。
callback (isActive: boolean) => void 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('activeStateChange', (isActive: boolean) => {
  console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
});

off('activeStateChange')10+

off(type: 'activeStateChange', callback?: (isActive: boolean) => void)

媒体控制器取消监听会话激活状态变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'activeStateChange'
callback (isActive: boolean) => void 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('activeStateChange');

on('validCommandChange')10+

on(type: 'validCommandChange', callback: (commands: Array<AVControlCommandType>) => void)

会话支持的有效命令变化监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'validCommandChange':当检测到会话的合法命令发生改变时,触发该事件。
callback (commands: Array<AVControlCommandType>) => void 回调函数。参数commands是有效命令的集合。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
});

off('validCommandChange')10+

off(type: 'validCommandChange', callback?: (commands: Array<AVControlCommandType>) => void)

媒体控制器取消监听会话有效命令变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'validCommandChange'
callback (commands: Array<AVControlCommandType>) => void 回调函数。参数commands是有效命令的集合。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('validCommandChange');

on('outputDeviceChange')10+

on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void

设置播放设备变化的监听事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件为'outputDeviceChange':当播放设备变化时,触发该事件)。
callback (state: ConnectionState, device: OutputDeviceInfo) => void 回调函数,参数device是设备相关信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
  console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
});

off('outputDeviceChange')10+

off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void

媒体控制器取消监听分布式设备变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'outputDeviceChange'
callback (state: ConnectionState, device: OutputDeviceInfo) => void 回调函数,参数device是设备相关信息。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('outputDeviceChange');

on('sessionEvent')10+

on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void

媒体控制器设置会话自定义事件变化的监听器。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'sessionEvent':当会话事件变化时,触发该事件。
callback (sessionEvent: string, args: {[key:string]: object}) => void 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => {
    console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
  });
}

off('sessionEvent')10+

off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void

媒体控制器取消监听会话事件的变化通知。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'sessionEvent'
callback (sessionEvent: string, args: {[key:string]: Object}) => void 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。
该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('sessionEvent');

on('queueItemsChange')10+

on(type: 'queueItemsChange', callback: (items: Array<AVQueueItem>) => void): void

媒体控制器设置会话自定义播放列表变化的监听器。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'queueItemsChange':当session修改播放列表时,触发该事件。
callback (items: Array<AVQueueItem>) => void 回调函数,items为变化的播放列表。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
  console.info(`OnQueueItemsChange, items length is ${items.length}`);
});

off('queueItemsChange')10+

off(type: 'queueItemsChange', callback?: (items: Array<AVQueueItem>) => void): void

媒体控制器取消监听播放列表变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'queueItemsChange'
callback (items: Array<AVQueueItem>) => void 回调函数,参数items是变化的播放列表。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('queueItemsChange');

on('queueTitleChange')10+

on(type: 'queueTitleChange', callback: (title: string) => void): void

媒体控制器设置会话自定义播放列表的名称变化的监听器。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'queueTitleChange':当session修改播放列表名称时,触发该事件。
callback (title: string) => void 回调函数,title为变化的播放列表名称。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.on('queueTitleChange', (title: string) => {
  console.info(`queueTitleChange, title is ${title}`);
});

off('queueTitleChange')10+

off(type: 'queueTitleChange', callback?: (title: string) => void): void

媒体控制器取消监听播放列表名称变化的事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'queueTitleChange'
callback (title: string) => void 回调函数,参数items是变化的播放列表名称。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('queueTitleChange');

on('extrasChange')10+

on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void

媒体控制器设置自定义媒体数据包事件变化的监听器。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'extrasChange':当媒体提供方设置自定义媒体数据包时,触发该事件。
callback (extras: {[key:string]: object}) => void 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

let avSessionController: avSession.AVSessionController | undefined = undefined;
let currentAVSession: avSession.AVSession | undefined = undefined;
let tag = "createNewSession";
let context: Context = getContext(this);

avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
  if (err) {
    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    currentAVSession = data;
  }
});
if (currentAVSession !== undefined) {
  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
    avSessionController = controller;
  }).catch((err: BusinessError) => {
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
  });
}

if (avSessionController !== undefined) {
  (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => {
    console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
  });
}

off('extrasChange')10+

off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void

媒体控制器取消监听自定义媒体数据包变化事件。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'extrasChange'
callback ({[key:string]: Object}) => void 注册监听事件时的回调函数。
该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

avsessionController.off('extrasChange');

getAVPlaybackStateSync10+

getAVPlaybackStateSync(): AVPlaybackState;

使用同步方法获取当前会话的播放状态。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
AVPlaybackState 当前会话的播放状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync();
} catch (err) {
  let error = err as BusinessError;
  console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`);
}

getAVMetadataSync10+

getAVMetadataSync(): AVMetadata

使用同步方法获取会话元数据。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
AVMetadata 会话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync();
} catch (err) {
  let error = err as BusinessError;
  console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`);
}

getAVCallState11+

getAVCallState(): Promise<AVCallState>

获取通话状态数据。结果通过Promise异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<AVCallState> Promise对象,返回通话状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => {
  console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
}).catch((err: BusinessError) => {
  console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
});

getAVCallState11+

getAVCallState(callback: AsyncCallback<AVCallState>): void

获取通话状态数据。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<AVCallState> 回调函数,返回通话状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
  if (err) {
    console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
  }
});

getCallMetadata11+

getCallMetadata(): Promise<CallMetadata>

获取通话会话的元数据。结果通过Promise异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Promise<CallMetadata> Promise对象,返回会话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => {
  console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
}).catch((err: BusinessError) => {
  console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
});

getCallMetadata11+

getCallMetadata(callback: AsyncCallback<CallMetadata>): void

获取通话会话的元数据。结果通过callback异步回调方式返回。

系统能力: SystemCapability.Multimedia.AVSession.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<CallMetadata> 回调函数,返回会话元数据。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
  if (err) {
    console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
  } else {
    console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
  }
});

getAVQueueTitleSync10+

getAVQueueTitleSync(): string

使用同步方法获取当前会话播放列表的名称。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
string 当前会话播放列表名称。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let currentQueueTitle: string = avsessionController.getAVQueueTitleSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`);
}

getAVQueueItemsSync10+

getAVQueueItemsSync(): Array<AVQueueItem>

使用同步方法获取当前会话播放列表相关信息。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Array<AVQueueItem> 当前会话播放列表队列。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`);
}

getOutputDeviceSync10+

getOutputDeviceSync(): OutputDeviceInfo

使用同步方法获取当前输出设备信息。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
OutputDeviceInfo 当前输出设备信息。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
}

isActiveSync10+

isActiveSync(): boolean

使用同步方法判断会话是否被激活。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
boolean 会话是否为激活状态,true表示被激活,false表示禁用。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let isActive: boolean = avsessionController.isActiveSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`);
}

getValidCommandsSync10+

getValidCommandsSync(): Array<AVControlCommandType>

使用同步方法获取会话支持的有效命令。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

返回值:

类型 说明
Array<AVControlCommandType> 会话支持的有效命令的集合。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
6600101 Session service exception.
6600102 The session does not exist.
6600103 The session controller does not exist.

示例:

import { BusinessError } from '@kit.BasicServicesKit';

try {
  let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync();
} catch (err) {
  let error = err as BusinessError;
  console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`);
}

AVControlCommandType10+

type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute'

会话可传递的命令。

该类型可取的值为下表字符串的并集。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

类型 说明
'play' 播放。
'pause' 暂停。
'stop' 停止。
'playNext' 下一首。
'playPrevious' 上一首。
'fastForward' 快进。
'rewind' 快退。
'seek' 跳转某一节点。
'setSpeed' 设置播放倍速。
'setLoopMode' 设置循环模式。
'toggleFavorite' 是否收藏。
'playFromAssetId' 播放指定的assetid。
'answer' 接听。
'hangUp' 挂断。
'toggleCallMute' 设置通话静音状态。

AVControlCommand10+

会话接受的命令的对象描述。

原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 类型 必填 说明
command AVControlCommandType 命令。
parameter LoopMode | string | number 命令对应的参数。

AVCastPickerOptions14+

拉起的投播半模态窗口相关属性。

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

名称 类型 必填 说明
sessionType AVSessionType 会话类型,默认值为'audio'。
当前仅支持'audio'、'video'会话类型。如果传入'voice_call'、'video_call',将按照传入默认值'audio'处理。

AVCastPickerHelper14+

投播半模态对象,可拉起半模态窗口,选择投播设备。在使用前,需要创建AVCastPickerHelper实例。

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

constructor14+

constructor(context: Context)

创建AVCastPickerHelper对象,获取context参考getContext

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
context Context 应用上下文(仅支持UIAbilityContext)。

示例:

import { common } from '@kit.AbilityKit';
import { avSession } from '@kit.AVSessionKit';
@Entry
@Component
struct Index {
  @State message: string = 'hello world';

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(40)
          .fontWeight(FontWeight.Bold)
          .onClick(()=>{
            let context = getContext(this) as common.Context;
            let avCastPicker = new avSession.AVCastPickerHelper(context);
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

select14+

select(options?: AVCastPickerOptions): Promise<void>

通过选择模式拉起AVCastPicker界面,用户可以选择投播设备。接口采用Promise异步返回形式,传入可选参数AVCastPickerOptions对象,无返回值。

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
options AVCastPickerOptions AVCastPicker选择选项。无此参数时,以AVCastPickerOptions默认值拉起。

返回值:

类型 说明
Promise<void> Promise对象。当命令发送成功,无返回结果,否则返回错误对象。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.

示例:

import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

async function avCastPicker(context: common.Context) {
  let avCastPickerOptions : avSession.AVCastPickerOptions = {
    sessionType : 'video',
  }
  let avCastPicker = new avSession.AVCastPickerHelper(context);
  avCastPicker.select(avCastPickerOptions).then(() => {
    console.info('select successfully');
  }).catch((err: BusinessError) => {
    console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`);
  });
}

on('pickerStateChange')14+

on(type: 'pickerStateChange', callback: Callback<AVCastPickerState>) : void

设置半模态窗口变化的监听事件。

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 事件回调类型,支持事件'pickerStateChange':当半模态窗口变化时,触发该事件。
callback Callback<AVCastPickerState> 回调函数,参数state是变化后的半模态窗口状态。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.

示例:

import { common } from '@kit.AbilityKit';
import { AVCastPickerState } from '@kit.AVSessionKit';

async function onPickerStateChange(context: common.Context) {
  let avCastPicker = new avSession.AVCastPickerHelper(context);
  avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => {
    console.info(`picker state change : ${state}`);
  });
}

off('pickerStateChange')14+

off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState>) : void

取消半模态窗口变化的监听事件,关闭后,不再进行该事件回调。

原子化服务API: 从API version 14开始,该接口支持在原子化服务中使用。

系统能力: SystemCapability.Multimedia.AVSession.AVCast

参数:

参数名 类型 必填 说明
type string 取消对应的监听事件,支持事件'pickerStateChange'
callback Callback<AVCastPickerState> 回调函数,参数state是变化后的半模态窗口状态。
当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。

错误码:

以下错误码的详细介绍请参见媒体会话管理错误码

错误码ID 错误信息
401 parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.

示例:

import { common } from '@kit.AbilityKit';

async function onPickerStateChange(context: common.Context) {
  let avCastPicker = new avSession.AVCastPickerHelper(context);
  avCastPicker.off('pickerStateChange');
}

AVSessionErrorCode10+

会话发生错误时的错误码。

名称 说明
ERR_CODE_SERVICE_EXCEPTION 6600101 会话服务端异常。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_SESSION_NOT_EXIST 6600102 会话不存在。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_CONTROLLER_NOT_EXIST 6600103 会话控制器不存在。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_REMOTE_CONNECTION_ERR 6600104 远端会话连接失败。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_COMMAND_INVALID 6600105 无效会话命令。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_SESSION_INACTIVE 6600106 会话未激活。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_MESSAGE_OVERLOAD 6600107 命令&消息过载。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_DEVICE_CONNECTION_FAILED 6600108 设备连接失败。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_REMOTE_CONNECTION_NOT_EXIST 6600109 远端会话不存在。
原子化服务API: 从API version 12开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.Core
ERR_CODE_CAST_CONTROL_UNSPECIFIED13+ 6611000 未被定义的投播错误码。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_REMOTE_ERROR13+ 6611001 远端播放器中发生不明错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_BEHIND_LIVE_WINDOW13+ 6611002 播放出现延迟。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_TIMEOUT13+ 6611003 投播控制进程超时。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_RUNTIME_CHECK_FAILED13+ 6611004 运行时检查失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PLAYER_NOT_WORKING13+ 6611100 跨设备数据传输被锁定。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_SEEK_MODE_UNSUPPORTED13+ 6611101 不支持指定的查找模式。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_ILLEGAL_SEEK_TARGET13+ 6611102 要搜索的位置超出媒体的范围,或者不支持当前搜索模式。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PLAY_MODE_UNSUPPORTED13+ 6611103 不支持指定的播放模式。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PLAY_SPEED_UNSUPPORTED13+ 6611104 不支持指定的播放速度。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DEVICE_MISSING13+ 6611105 操作失败,因为媒体源设备或媒体接收器设备已被销毁。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_INVALID_PARAM13+ 6611106 该参数无效。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_NO_MEMORY13+ 6611107 内存分配失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_OPERATION_NOT_ALLOWED13+ 6611108 不被允许的操作。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_UNSPECIFIED13+ 6612000 未指定的输入/输出错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_FAILED13+ 6612001 网络连接失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_TIMEOUT13+ 6612002 网络连接超时。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_INVALID_HTTP_CONTENT_TYPE 13+ 6612003 无效的"Content-Type"。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_BAD_HTTP_STATUS13+ 6612004 HTTP服务器返回一个意外的HTTP响应状态码。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_FILE_NOT_FOUND13+ 6612005 文件不存在。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NO_PERMISSION13+ 6612006 不允许执行输入/输出的IO操作。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_CLEARTEXT_NOT_PERMITTED13+ 6612007 应用的网络安全配置不允许访问明文HTTP流量。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_READ_POSITION_OUT_OF_RANGE13+ 6612008 从数据绑定中读取数据。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NO_CONTENTS13+ 6612100 媒体中没有可播放的内容。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_READ_ERROR13+ 6612101 媒体无法读取。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_CONTENT_BUSY13+ 6612102 该资源正在使用中。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_CONTENT_EXPIRED13+ 6612103 输入/输出的IO请求内容已过期。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_USE_FORBIDDEN13+ 6612104 不允许播放请求内容。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NOT_VERIFIED13+ 6612105 无法验证所允许的内容。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_EXHAUSTED_ALLOWED_USES13+ 6612106 此内容已达到允许的最大使用次数。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_IO_NETWORK_PACKET_SENDING_FAILED13+ 6612107 从源设备发送数据包到接收设备时出现错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PARSING_UNSPECIFIED13+ 6613000 未指定的内容解析错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_MALFORMED13+ 6613001 媒体容器比特流的格式解析错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_MALFORMED13+ 6613002 媒体清单解析错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_UNSUPPORTED13+ 6613003 文件的媒体容器格式/媒体容器特性不被支持。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_UNSUPPORTED13+ 6613004 媒体清单中不支持的特性。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_UNSPECIFIED13+ 6614000 未指定的解码错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_INIT_FAILED13+ 6614001 解码器初始化失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_QUERY_FAILED13+ 6614002 解码器查询失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_FAILED13+ 6614003 媒体样本解码失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_FORMAT_EXCEEDS_CAPABILITIES13+ 6614004 设备的能力无法解码当前格式。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DECODING_FORMAT_UNSUPPORTED13+ 6614005 不支持的解码格式。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_UNSPECIFIED13+ 6615000 未指定的音频渲染器错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_INIT_FAILED 13+ 6615001 音频渲染器初始化失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_WRITE_FAILED13+ 6615002 音频渲染器写入数据失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_UNSPECIFIED13+ 6616000 未指定的DRM相关错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_SCHEME_UNSUPPORTED13+ 6616001 设备不支持所选择的DRM保护方案。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_PROVISIONING_FAILED13+ 6616002 设备配置失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_CONTENT_ERROR13+ 6616003 受DRM保护的内容无法播放。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_LICENSE_ACQUISITION_FAILED13+ 6616004 获取许可证失败。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_DISALLOWED_OPERATION13+ 6616005 许可证策略不允许该操作。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_SYSTEM_ERROR13+ 6616006 DRM系统中发生错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_DEVICE_REVOKED13+ 6616007 设备已撤销DRM权限。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_LICENSE_EXPIRED13+ 6616008 加载中的DRM许可证已过期。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast
ERR_CODE_CAST_CONTROL_DRM_PROVIDE_KEY_RESPONSE_ERROR13+ 6616100 DRM处理密钥响应时发生错误。
原子化服务API: 从API version 13开始,该接口支持在原子化服务中使用。
系统能力: SystemCapability.Multimedia.AVSession.AVCast

SkipIntervals11+

表示session支持的快进快退时间间隔的枚举。

系统能力: SystemCapability.Multimedia.AVSession.Core

名称 说明
SECONDS_10 10 时间为10秒。
SECONDS_15 15 时间为15秒。
SECONDS_30 30 时间为30秒。