human: 如何处理七牛云的实时音视频QNRemoteAudioTrack

gpt: [实时音视频](https://developer.qiniu.com/rtc) > API 文档 > Web >QNRemoteAudioTrack

#  QNRemoteAudioTrack

最近更新时间: 2022-07-14 14:50:22

远端音频 Track

Hierarchy

  * EventEmitter 
    * [QNTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9076/WebQNTrack)
      * [QNLocalTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9085/WebQNLocalTrack)
        * [QNLocalVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9061/WebQNLocalVideoTrack)
          * [QNCameraVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9068/WebQNCameraVideoTrack)
          * [QNScreenVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9092/WebQNScreenVideoTrack)
          * [QNCanvasVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/10320/WebQNCanvasVideoTrack)
          * [QNCustomVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9088/WebQNCustomVideoTrack)
        * [QNLocalAudioTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9089/WebQNLocalAudioTrack)
          * [QNMicrophoneAudioTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9064/WebQNMicrophoneAudioTrack)
          * [QNBufferSourceAudioTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9069/WebQNBufferSourceAudioTrack)
          * [QNCustomAudioTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9091/WebQNCustomAudioTrack)
      * [QNRemoteTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9082/WebQNRemoteTrack)
        * [QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9060/WebQNRemoteVideoTrack)
        * QNRemoteAudioTrack 

Index

Properties

  * trackID
  * userID
  * tag
  * mediaElement

Event

  * mute-state-changed
  * audioFrame

Core Methods

  * play
  * isAudio
  * isVideo
  * isMuted
  * getMediaStreamTrack
  * isSubscribed
  * setVolume
  * setPlaybackDevice
  * getVolumeLevel
  * getCurrentTimeDomainData
  * getCurrentFrequencyDomainData
  * getStats

Properties

trackID

  * trackID?: string
  * Track ID

对于本地 Track，当且仅当 Track 发布后才可获取到有效的 TrackID；对于远端 Track，可随时获取到有效的 TrackID。

userID

  * userID?: string
  * 用户 ID

tag

  * tag?: string
  * 自定义 tag 文本

mediaElement

  * mediaElement: HTMLVideoElement | HTMLAudioElement | undefined
  * 当前播放元素，当调用 play 方法后，可以通过该属性获取播放的媒体元素

Event

mute-state-changed

  * (isMuted: boolean): void
  * mute 状态变化

> 音视频 Track 静默状态改变时触发此事件。

Parameters

    * isMuted: boolean 

是否 muted

audioFrame

  * (buffer: [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer)): void
  * 原始音频数据返回
    
        track.on('audioFrame', function(buffer) {
       console.log('audioFrame', buffer);
    })

Parameters

    * buffer: [AudioBuffer](https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer)

远端音频轨道的音频帧

Core Methods

play

  * public play(container: HTMLElement, config?: QNPlayerConfig): Promise<void>
  * 播放当前 track

Parameters

    * container: HTMLElement 

挂载的 html 容器，SDK 会在该容器下创建 audio 或 video 元素来播放 track

    * Optional config: [QNPlayerConfig](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/10141/WebQNPlayerConfig)

播放配置信息

Returns void

isAudio

  * isAudio(): boolean
  * 是否是音频

Returns boolean

isVideo

  * isVideo(): boolean
  * 是否是视频

Returns boolean

isMuted

  * isMuted(): boolean
  * 是否 mute（静音）

Returns boolean

getMediaStreamTrack

  * getMediaStreamTrack(): MediaStreamTrack | undefined
  * 获取浏览器原生的 MediaStreamTrack 对象

Returns MediaStreamTrack | undefined

isSubscribed

  * isSubscribed(): boolean
  * 是否已订阅

Returns boolean

setVolume

  * setVolume(volume: number): void
  * 设置音量

> 音量值在 0 - 1 之间为软件缩小；1 为原始音量；大于 1 且小于 100 为软件放大。
>
> 该设置可以用于适度对采集音量做放大或者缩小。

Parameters

    * volume: number 

音量值为0-100

Returns void

setPlaybackDevice

  * setPlaybackDevice(deviceId: string): Promise<void>
  * 设置音频输出设备

Parameters

    * deviceId: string 

设备 deviceId，可以从
[QNRTC.getPlaybackDevices](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9070)
接口中获取

Returns Promise<void>

getVolumeLevel

  * getVolumeLevel(): string ｜ undefined
  * 获取当前音量

> 可通过定时调用该方法获取音量值的方式来判断当前用户是否在讲话。
>
> 在安静的环境下，获取到大于 0 的数值为预期现象，您可根据您的需求自行决定判断的阈值。

Returns string | undefined

getCurrentTimeDomainData

  * getCurrentTimeDomainData(): Uint8Array | undefined
  * 获取当前时域数据

Returns Uint8Array | undefined

getCurrentFrequencyDomainData

  * getCurrentFrequencyDomainData(): Uint8Array | undefined
  * 获取当前频域数据

Returns Uint8Array | undefined

getStats

  * getStats(): [QNRemoteAudioTrackStats](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9093/WebQNRemoteAudioTrackStats)
  * 获取当前频域数据

Returns
[QNRemoteAudioTrackStats](https://developer.qiniu.com/rtc/9087/WebQNRemoteAudioTrack/9093/WebQNRemoteAudioTrackStats)

以上内容是否对您有帮助？