Home > Web Front-end > uni-app > body text

How to introduce Tencent Cloud Player in uniapp

PHPz
Release: 2023-04-18 16:01:17
Original
1907 people have browsed it

With the continuous development of technology, people's demand for and reliance on video media is also increasing. On the mobile side, many applications require video playback functions, but they face many problems when implementing video playback. In order to solve these problems, Internet companies have launched their own video players, and Tencent Cloud is no exception.

Tencent Cloud Player is a smooth, stable, and easy-to-use player that not only supports video playback in multiple formats, but also supports a high degree of customization to meet the individual needs of developers. This article mainly describes how to introduce Tencent Cloud Player into the uniapp framework.

1. Register a Tencent Cloud account

Before introducing the Tencent Cloud player, you need to register a Tencent Cloud account, open the official website, and follow the prompts to register. After successful registration, enter the console, find "Video Service" in "Products and Services" on the left, and create a video service account.

2. Create a player

Log in to the console, find "Cloud On Demand" in "Video Services" on the left, click to enter and find "Player Management", click "New "Create a new player. Set the player name, select the default picture, label, fill in the cover and other information.

3. Obtain the player code

After creating the player, click the player name to enter the "Management Page", find "Generate Embed Code" in the menu bar, and select videos, payment, etc. as needed Basic Information. Modify the generated code to adapt to the mobile interface.

4. Introducing Tencent Cloud Player into uniapp

In uniapp development, the js code and style file of Tencent Cloud Player need to be introduced into the page. The code is as follows:

<script src=&#39;https://qcloud.qq.com/xxx/js/tcplayer-2.4.0.min.js&#39;></script>
<link rel=&#39;stylesheet&#39; href=&#39;https://qcloud.qq.com/xxx/css/tcplayer.css&#39;>
Copy after login

Among them, the links of src and href need to be modified according to the specific code generation. The code is placed in the App.vue file of uniapp and is guaranteed to be loaded when the application starts.

5. Using Tencent Cloud Player

The method of using Tencent Cloud Player in uniapp is basically the same as introducing the player into an ordinary HTML page. In the page where the player needs to be used, create a video tag through js code, and then pass the video address, player size, customized UI and other parameters required by Tencent Cloud Player to Tencent Cloud Player. The code is as follows:

<template>
   <view>
       <video id=&#39;videoplayer&#39;/>
   </view>
</template>

<script>
    export default {
        onReady() {
            var player = new TcPlayer('videoplayer', {
                "m3u8": 'http://xxx.m3u8', //视频地址
                "width": 640, //视频宽度
                "height": 360 //视频高度
            });
        }
    }
</script>
Copy after login

It should be noted that when using Tencent Cloud Player, its initialization needs to be placed in the onReady() function to ensure that it is initialized after the page is loaded. If the video tag is written in the template, it needs to be referenced by the tag's id during initialization. The videoplayer here can be customized.

Summary:

The above are the main steps to introduce Tencent Cloud Player into uniapp. Through the above simple steps, you can improve the video playback effect in mobile applications to a higher level. It should be noted that for a better user experience, we can make some customized settings for the player. In addition, Tencent Cloud has many other products and services that are worth understanding and using.

The above is the detailed content of How to introduce Tencent Cloud Player in uniapp. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template