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

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

#  QNLocalTrack

最近更新时间: 2022-07-14 14:48:46

本地 Track

Hierarchy

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

Index

Properties

  * trackID
  * userID
  * tag
  * mediaElement

Event

  * ended

Core Methods

  * play
  * isAudio
  * isVideo
  * isMuted
  * getMediaStreamTrack
  * setMuted
  * destroy

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

ended

  * (): void
  * Track 断开
    
        track.on('ended', function() {
        console.log('ended')
    })

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/9085/WebQNLocalTrack/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

setMuted

  * setMuted(isMuted: boolean): void
  * 设置是否静默该 track，静默后，SDK 将会发送静默帧数据

当静默状态改变后，远端订阅 track 将会收到 [mute-state-
changed](https://developer.qiniu.com/rtc/9085/WebQNLocalTrack/9082) 事件。

Parameters

    * isMuted: boolean 

是否 mute

Returns void

destroy

  * destroy(): void
  * 销毁当前流

Returns void

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