High-quality Interactive Audio/Video Uni-app SDK

Overview

如何使用

步骤一:注册并创建 uni-app 账号

搭建 App 开发环境步骤如下:

  1. 下载 HBuilderX 编辑器

    项目中 HBuilderX 目前使用的最新版本,如果此前下载过 HBuilderX,为保证开发环境统一请更新到最新版本。

  2. DCloud 开发者中心注册 之后登录 HBuilderX 编辑器。

步骤二:创建应用并开通腾讯云服务

1. 创建实时音视频 TRTC 应用

2. 获取 TRTC 密钥信息

  • 应用管理 > 应用信息 中获取 SDKAppID 信息。
  • 应用管理 > 快速上手 中获取应用的 secretKey 信息。

首次创建实时音视频应用的腾讯云账号,可获赠一个 10000 分钟的音视频资源免费试用包。

步骤三:获取 uni-app SDK,并引入工程

  1. 购买 uni-app SDK 插件: 登录 uni 原生插件市场,在插件详情页中购买(免费插件也可以在插件市场 0 元购)。购买后才能够云端打包使用插件。购买插件时请选择正确的 appid,以及绑定正确包名
  2. 使用自定义基座打包 uni 原生插件 (请使用真机运行自定义基座)。 使用 uni 原生插件必须先提交云端打包才能生效,购买插件后在应用的 manifest.json 页面的 App 原生插件配置 项下单击选择云端插件,选择需要打包的插件。 直接云端打包后无法打 log,不利于排错,所以一般先打一个自定义基座,把需要的原生插件打到真机运行基座里,然后在本地写代码调用调试。
  • 自定义基座不是正式版,真正发布时,需要再打正式包。使用自定义基座是无法正常升级替换 APK 的。
  • 请尽量不要使用本地插件,插件包超过自定义基座的限制,可能导致调试收费

步骤四:下载「js 封装层」SDK 中的 TrtcCloud 代码,并引入工程

基础使用

注意事项

  • 插件是 uni-app 原生插件,使用前请了解 uni-app 原生插件使用方法,官方教程:uni 原生插件使用教程
  • 使用视频功能时,页面必须使用 .nvue 文件构建。因为扩展的 component 只能在 .nvue 文件中使用,不需要引入即可直接使用。目前的插件中包含扩展 component,用来显示视频流。详情可参考:https://nativesupport.dcloud.net.cn/NativePlugin/course/ios

初始化

import TrtcCloud from "@/TrtcCloud/lib/index";
this.trtcCloud = TrtcCloud.createInstance();

事件监听

进房事件

this.trtcCloud.on("onEnterRoom", (result) => {
  if (result > 0) {
    console.log(`进房成功,耗时: ${result}ms`);
  }
});

退房事件

this.trtcCloud.on("onExitRoom", (reason) => {
  console.log(`退房 ${reason}`);
});

远端进房

this.trtcCloud.on("onRemoteUserEnterRoom", (userId) => {
  console.log(`远端进房: userId = ${userId}`);
});

远端视频流

this.trtcCloud.on("onUserVideoAvailable", (res) => {
  const { userId, available } = res;
  if (userId && available) {
    this.remoteUserId = userId;
  }
});

进入房间

const param = { roomId, userId, sdkAppId, userSig };
this.trtcCloud.enterRoom(param, appScene);

开启音视频通话

在成功登入房间后,可调用 startPreview 开启音视频

<template>
  <div>
    <trtc-local-view :userId="userId" style="height: 400rpx; flex: 1;"></trtc-local-view>
  </div>
</template>
<script>
  import TrtcLocalView from '@/TrtcCloud/view/TrtcLocalView';

  export default {
    components: {
      TrtcLocalView
    },
    methods: {
      startLocalPreview() {
        // 需要在登入房间之后才能开启音视频通话
        this.trtcCloud.startLocalPreview(true, this.userId);
      }
    }
  }
</script>

拉取其他用户音视频

<template>
  <div>
    <trtc-remote-view v-if="remoteUserId" :userId="remoteUserId" :viewId="remoteUserId" style="height: 400rpx; flex: 1"></trtc-remote-view>
  </div>
</template>
<script>
  import TrtcRemoteView from '@/TrtcCloud/view/TrtcRemoteView';

  export default {
    components: {
      TrtcRemoteView
    },
    methods: {
      startRemoteView() {
        // 拉取远端音视频
        this.trtcCloud.startRemoteView(this.remoteUserId, 0, this.remoteUserId)
      }
    }
  }
</script>

退出房间

exitRoom() {
  try {
    this.stopLocalPreview();
    this.stopRemoteView();
    this.trtcCloud.exitRoom();
  } catch (e) {
    // handle the exception
  }
},

销毁实例

destroyInstance() {
  if (this.trtcCloud) {
    TrtcCloud.destroyInstance();
    this.trtcCloud = null;
  }
}

技术咨询

了解更多详情您可 QQ 咨询:309869925 (技术交流群)

You might also like...

Enables video and audio tags in all major browsers.

HTML5 video made easy All it takes is a single line of code to make HTML5 video and audio tags work in all major browsers. How to enable video and aud

Dec 17, 2022

HTML5 audio or video player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

HTML5 <audio> or <video> player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

Dec 27, 2022

HTML5 audio or video player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

HTML5 <audio> or <video> player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

Jan 8, 2023

jPlayer : HTML5 Audio & Video for jQuery

jPlayer : HTML5 Audio & Video for jQuery Gitter Support for Zepto 1.0+ compiled with the data module. What is jPlayer? jPlayer is a jQuery/Zepto plugi

Dec 27, 2022

Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications

RTC SCORE Library to calculate a Mean Opinion Score (MOS) from 1 to 5 for audio and video real time communications. The first version of the algorithm

Nov 27, 2022

Secretly record audio and video with chromium based browsers

snoop TCC restricts access to the device camera and microphone to protect user data from unauthorized access. But... If you trusted your browser with

Aug 30, 2022

Resurrection of mediagroup / MediaController (renamed) which can be used to sync and control multiple audio / video elements.

media-group (examples) Resurrection of the mediagroup attribute and MediaController API (but renamed) which can be used to sync and control multiple a

Dec 15, 2022

Resurrection of mediagroup / MediaController (renamed) which can be used to sync and control multiple audio / video elements.

media-group (examples) Resurrection of the mediagroup attribute and MediaController API (but renamed) which can be used to sync and control multiple a

Aug 2, 2022

This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library included.

Aim-Player This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library incl

Jun 27, 2021
Owner
LiteAVSDK
high-quality interactive audio/video services, eg: rtc、live etc
LiteAVSDK
A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

SoundJS SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, inclu

CreateJS 4.3k Dec 31, 2022
Audio visualizer library for javascript. Create dynamic animations that react to an audio file or audio stream.

Wave.js Audio visualizer library for javascript. Installation Install With CDN <script src="https://cdn.jsdelivr.net/gh/foobar404/wave.js/dist/bundle.

Austin Michaud λ 497 Dec 21, 2022
High-quality WebRTC SDK

腾讯云实时音视频 TRTC SDK 产品介绍 腾讯实时音视频(Tencent Real-Time Communication,TRTC),将腾讯多年来在网络与音视频技术上的深度积累,以多人音视频通话和低延时互动直播两大场景化方案,通过腾讯云服务向开发者开放,致力于帮助开发者快速搭建低成本、低延时、高

LiteAVSDK 58 Dec 18, 2022
A high-performance, interactive and customizable video player control, built upon Reanimated v2 & GestureHandler v2

`JSThread` to `JSThread`, `UIThread` to `UIThread`. React Native Reanimated Expo Player 100% written in Typescript video player component, interaction

Alan Toa 58 Jan 4, 2023
:musical_score: ts-audio is an agnostic library that makes it easy to work with AudioContext and create audio playlists in the browser

ts-audio · ts-audio is an agnostic and easy-to-use library to work with the AudioContext API and create Playlists. Features Simple API that abstracts

Evandro Leopoldino Gonçalves 284 Dec 25, 2022
AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.

Documentation • Examples • Tutorials • Support Us • Get Professional Help AmplitudeJS is a lightweight JavaScript library that allows you to control t

Server Side Up 3.9k Jan 2, 2023
Advanced Music Bot It is an advance type of discord music bot which plays high quality of music with spotify

Advanced Music Bot It is an advance type of discord music bot which plays high quality of music with spotify, apple music support . You can save your songs and play it. It also has DJ mode system.

Diwas Atreya 65 Dec 25, 2022
High-quality* music player.

Laudiolin A very simple music player written in TypeScript using Tauri and React. pronounced eL-auDiO-liN Running Clone the project run npm i run npm

null 12 Dec 21, 2022
Frontend for a social audio & video app

LɪᴛᴛʟᴇAᴘᴇ littleape is a frontend for the free social audio & video social-media platform greatape. littleape, via greatape, is a Fediverse technology

Charles Iliya Krempeaux 2 Sep 7, 2022
Rip video from p***hub at highest quality

PH4K Rip video from p***hub at it's highest quality. Install Install nodejs. Install ts-node globally: npm i -g ts-node. Install Chrome to default pat

SHINCHVEN 2 Oct 22, 2022