add transcode and sign
This commit is contained in:
1 parent
c26fba65a2
commit
c020564dc2
9 files changed
+157
-17
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<vue-plyr ref="plyr" :options="options">
|
||||
<video ref="video" controls playsinline :data-poster="preview" :src="resource"></video>
|
||||
<video ref="video" controls playsinline :data-poster="preview"></video>
|
||||
</vue-plyr>
|
||||
</template>
|
||||
|
||||
@@ -10,6 +10,7 @@ import VuePlyr from 'vue-plyr';
|
||||
import 'vue-plyr/dist/vue-plyr.css';
|
||||
// import Hls from 'hls.js';
|
||||
// import Plyr from 'plyr';
|
||||
import TcAdapter from 'tcadapter';
|
||||
|
||||
interface IData {
|
||||
options: {};
|
||||
@@ -21,7 +22,11 @@ export default defineComponent({
|
||||
VuePlyr
|
||||
},
|
||||
props: {
|
||||
resource: {
|
||||
fileId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
sign: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
@@ -40,6 +45,23 @@ export default defineComponent({
|
||||
this.player?.stop();
|
||||
},
|
||||
mounted() {
|
||||
if (!TcAdapter.isSupported()) {
|
||||
throw new Error('current environment can not support TcAdapter');
|
||||
}
|
||||
|
||||
const adapter = new TcAdapter(
|
||||
this.$refs.video,
|
||||
{
|
||||
appID: '1500015562',
|
||||
fileID: this.fileId,
|
||||
psign: this.sign,
|
||||
hlsConfig: {}
|
||||
},
|
||||
() => {
|
||||
console.log('basicInfo', adapter.getVideoBasicInfo());
|
||||
}
|
||||
);
|
||||
|
||||
this.player = (this.$refs.plyr as typeof VuePlyr).player;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,5 +4,6 @@ export default {
|
||||
needPay: '需要购买',
|
||||
wechatPayHelp: '请打开手机微信,扫一扫完成支付',
|
||||
createOrderFailed: '创建订单失败',
|
||||
creatingOrder: '正在生成订单'
|
||||
creatingOrder: '正在生成订单',
|
||||
transcoding: '为保护版权,正在转码生成专属视频...'
|
||||
};
|
||||
@@ -10,7 +10,23 @@
|
||||
</el-col>
|
||||
<el-col :span="19" class="main">
|
||||
<div v-if="paid === true || episode?.isFree">
|
||||
<episode-player v-if="resource?.url" :resource="resource?.url" :preview="episode?.thumbnail" />
|
||||
<episode-player
|
||||
v-if="prepared && resource?.fileId && resource.sign"
|
||||
:file-id="resource?.fileId"
|
||||
:preview="episode?.thumbnail"
|
||||
:sign="resource.sign"
|
||||
/>
|
||||
<div v-else class="transcode">
|
||||
<el-alert
|
||||
:title="$t('course.message.transcoding')"
|
||||
type="info"
|
||||
center
|
||||
show-icon
|
||||
:closable="false"
|
||||
class="info"
|
||||
/>
|
||||
<el-progress :percentage="50" status="exception" :indeterminate="true" :show-text="false" class="progress" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="paid === false && !episode?.isFree">
|
||||
{{ $t('course.message.needPay') }}
|
||||
@@ -21,7 +37,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { episodeService } from '@/services/episode/service';
|
||||
import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse } from '@/services/episode/types';
|
||||
import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse, IEpisodeSignResponse } from '@/services/episode/types';
|
||||
import { defineComponent } from 'vue';
|
||||
import EpisodeSideList from '@/components/episode/SideList.vue';
|
||||
import EpisodePlayer from '@/components/episode/Player.vue';
|
||||
@@ -36,7 +52,9 @@ interface IData {
|
||||
resource: IResource | undefined;
|
||||
episodes: IEpisode[];
|
||||
loading: boolean;
|
||||
prepared: boolean;
|
||||
paid: boolean | undefined;
|
||||
sign: string | undefined;
|
||||
// id: number;
|
||||
// courseId: number;
|
||||
}
|
||||
@@ -55,7 +73,9 @@ export default defineComponent({
|
||||
loading: false,
|
||||
episodes: [],
|
||||
resource: undefined,
|
||||
paid: undefined
|
||||
paid: undefined,
|
||||
sign: undefined,
|
||||
prepared: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -72,11 +92,6 @@ export default defineComponent({
|
||||
this.loading = false;
|
||||
this.episode = data;
|
||||
});
|
||||
episodeService.resource(this.id).then(({ data: data }: { data: IResourceDetailResponse }) => {
|
||||
// this.loading = false;
|
||||
// this.episode = data;
|
||||
this.resource = data;
|
||||
});
|
||||
courseService.paid(this.courseId).then(({ data: { paid } }: { data: ICoursePaidStatusResponse }) => {
|
||||
this.paid = paid;
|
||||
});
|
||||
@@ -86,8 +101,22 @@ export default defineComponent({
|
||||
courseService.get(this.courseId).then(({ data: data }: { data: ICourseDetailResponse }) => {
|
||||
this.course = data;
|
||||
});
|
||||
this.onPrepareResouce();
|
||||
},
|
||||
methods: {
|
||||
onPrepareResouce() {
|
||||
episodeService.resource(this.id).then(({ data: data }: { data: IResourceDetailResponse }) => {
|
||||
this.resource = data;
|
||||
if (data.sign) {
|
||||
this.prepared = true;
|
||||
}
|
||||
});
|
||||
if (!this.prepared) {
|
||||
setTimeout(() => {
|
||||
this.onPrepareResouce();
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
onChoose(episode: IEpisode) {
|
||||
this.$router.push({
|
||||
...this.$route,
|
||||
@@ -115,5 +144,22 @@ $width: 300px;
|
||||
}
|
||||
.main {
|
||||
width: calc(100% - $width);
|
||||
background-image: radial-gradient(circle at 0 2%, #283e63, #172337 99%);
|
||||
}
|
||||
|
||||
.transcode {
|
||||
width: 300px;
|
||||
height: 200px;
|
||||
margin: auto;
|
||||
top: 50%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(0, -50%);
|
||||
.progress {
|
||||
margin: auto;
|
||||
}
|
||||
.info {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import httpClient from '../instance';
|
||||
import { IResourceDetailResponse } from '../resource/types';
|
||||
import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse } from './types';
|
||||
import { IEpisode, IEpisodeDetailResponse, IEpisodeListResponse, IEpisodeSignResponse } from './types';
|
||||
|
||||
class EpisodeService {
|
||||
key = 'episodes';
|
||||
@@ -15,7 +15,11 @@ class EpisodeService {
|
||||
}
|
||||
|
||||
async resource(id: number): Promise<AxiosResponse<IResourceDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}/resource/`);
|
||||
return await httpClient.post(`/${this.key}/${id}/resource/`);
|
||||
}
|
||||
|
||||
async sign(id: number): Promise<AxiosResponse<IEpisodeSignResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}/sign/`);
|
||||
}
|
||||
|
||||
async create(data: IEpisode): Promise<AxiosResponse<IEpisodeDetailResponse>> {
|
||||
|
||||
@@ -22,4 +22,8 @@ export interface IEpisodeListResponse {
|
||||
items: IEpisode[];
|
||||
}
|
||||
|
||||
export interface IEpisodeSignResponse {
|
||||
sign: string;
|
||||
}
|
||||
|
||||
export type IEpisodeDetailResponse = IEpisode;
|
||||
@@ -1,10 +1,13 @@
|
||||
export interface IResource {
|
||||
id: string;
|
||||
url?: string;
|
||||
state?: string;
|
||||
taskId?: string;
|
||||
fileId?: string;
|
||||
transcodeTaskState?: string;
|
||||
uploadTaskState?: string;
|
||||
transcodeTaskId?: string;
|
||||
uploadTaskId?: string;
|
||||
watermarks?: string[];
|
||||
episode?: number;
|
||||
sign?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user