HarmonyOS实战—影视类卡片应用(二)

简介: HarmonyOS实战—影视类卡片应用(二)

视频播放页面


主页我们已经完全实现了。下面,需要实现点击这些视频展示图片跳转的视频播放页面。我们先来看看其最终的效果图:


页面(pagevideo.hml)

这里,我们先剖析一下这个界面有哪些东西?


顶部的视频播放组件:<video>

Vip会员橙色按钮:<button>

图像金字塔以及视频的简介:标题<text>、评分<text>、vip<image>、播放量以及简介<text>。

点赞,喜欢,下载,搜藏:4个<image>。

专辑列表:<text>

其他推荐列表:<list>


既然,我们已经分析出来了界面的布局,那么直接上代码即可。示例如下:

<div style="flex-direction : column;">
    <video id='videoId' src='{{ mp4_url }}' muted='false' autoplay='false' poster='{{ url }}' controls="true"
           onprepared='preparedCallback' onstart='startCallback' onpause='pauseCallback' onfinish='finishCallback'
           onerror='errorCallback' onseeking='seekingCallback' onseeked='seekedCallback'
           ontimeupdate='timeupdateCallback' style="object-fit : fill; width : 100%; height : 250px;"
           onlongpress='change_fullscreenchange' onclick="change_start_pause"/>
    <div class="div_list">
        <button class="vip_button">VIP会员低至30元每季度,618狂欢进行中</button>
        <text class="text_title">{{ title }}</text>
        <div class="div_row">
            <text class="div_row_text">7.5分</text>
            <image class="div_row_image" src="../../../common/images/vip.png"/>
            <text class="div_row_text">2333.3万次播放 · 简介 ></text>
        </div>
        <div class="div_row">
            <image class="div_row2_image" src="../../../common/images/dianzan.png"/>
            <div class="div_row2">
                <image class="div_row2_image" src="../../../common/images/like.png"/>
                <image class="div_row2_image" src="../../../common/images/download.png"/>
                <image class="div_row2_image" src="../../../common/images/share.png"/>
            </div>
        </div>
        <text style="font-size : 15px; font-weight : bold;margin-top: 10px;">专辑列表</text>
        <div class="container">
            <list class="list" divider="true">
                <list-item for="{{responseData.vipList}}" class="list_item">
                    <image class="list_image" src="{{$item.img_url}}"/>
                    <text class="list_title">{{$item.title}}</text>
                </list-item>
            </list>
        </div>
    </div>
</div>


用户交互(pagevideo.js)

从上面的界面中,我们除了返现各种搭配的组件之外。还可以明显看到,专辑列表的视频推荐是从网络获取的,视频的播放交互,需要JS操作。


而且,最重要的是我们从前面主页传递过来的参数,如何获取呢?代码如下所示:

import fetch from '@system.fetch';
import router from '@system.router';
export default {
    data: {
        title: 'World',
        url: "",
        mp4_url: "",
        event: '',
        seekingtime: '',
        timeupdatetime: '',
        seekedtime: '',
        isStart: true,
        isfullscreenchange: false,
        duration: '',
        responseData:'正在加载中',
    },
    seekingCallback: function (e) {
        this.seekingtime = e.currenttime;
    },
    timeupdateCallback: function (e) {
        this.timeupdatetime = e.currenttime;
    },
    change_start_pause: function () {
        if (this.isStart) {
            this.$element('vedioId').pause();
            this.isStart = false;
        } else {
            this.$element('vedioId').start();
            this.isStart = true;
        }
    },
    change_fullscreenchange: function () { //全屏
        if (!this.isfullscreenchange) {
            this.$element('videoId').requestFullscreen({
                screenOrientation: 'default'
            });
            this.isfullscreenchange = true;
        } else {
            this.$element('vedioId').exitFullscreen();
            this.isfullscreenchange = false;
        }
    },
    fetch: function () {
        var that = this;
        fetch.fetch({
            url: 'https://liyuanjing-1300376177.cos.ap-shanghai.myqcloud.com/viptopmodel.json',
            success: function (response) {
                console.info("网络请求成功");
                that.responseData = JSON.parse(response.data);
                console.info(that.responseData.vipList[0].title);
            },
            fail: function () {
                console.info("网络请求错误");
            }
        });
    },
    onInit() {
        this.url = decodeURIComponent(this.data1);
        this.mp4_url = decodeURIComponent(this.data2);
        this.title= decodeURIComponent(this.data3);
        this.fetch();
    }
}


可以发现,鸿蒙开发获取参数非常简单,你怎么传递的参数,就是什么名字,这里就不在赘述了。


界面样式(pagevideo.css)

最后,就是我们的视频播放页面的界面样式。示例代码如下所示:

.div_list {
    flex-direction: column;
    margin: 10px;
}
.div_row {
    flex-direction: row;
    margin-top: 5px;
}
.div_row_text {
    font-size: 10px;
    font-family: sans-serif;
    color: darkgrey;
}
.div_row_image {
    width: 20px;
    height: 20px;
    margin-left: 10px;
    margin-right: 10px;
}
.div_row2 {
    flex-direction: row;
    position: absolute;
    right: 0;
}
.div_row2_image {
    width: 30px;
    height: 30px;
    margin-left: 10px;
    margin-right: 20px;
    margin-left: -2px;
    left: 0;
}
.text_title {
    font-size: 20px;
    font-family: sans-serif;
    font-weight: bold;
    margin-top: 10px;
}
.vip_button {
    background-color: darkorange;
    font-size: 20px;
    font-family: sans-serif;
    color: aqua;
    border-radius: 0px;
    box-shadow: 2px 2px 5px 2px #FF7F00;
    padding: 10px;
}
.container {
    display: flex;
    justify-content: center;
    align-items: center;
    left: 0px;
    top: 0px;
    width: 454px;
    height: 454px;
}
.list {
    width: 100%;
    margin-top: 10px;
    divider-color: #32CD99;
}
.list_item {
    width: 100%;
    flex-direction: row;
    margin-top: 5px;
    padding-bottom: 5px;
}
.list_title {
    text-align: center;
    height: 100px;
    font-size: 15px;
    font-weight: bold;
    color: coral;
    margin-left: 10px;
}
.list_image {
    width: 200px;
    height: 100px;
    border-radius: 5px;
}


其他设置

默认应用是不支持网络请求的,也就是说,纯粹使用上面的代码。肯定会报错,那么我们如何赋予应用网络权限呢?


只需要在config.json文件中,添加如下代码即可:


"module": {
    "reqPermissions": [
      {
        "name": "ohos.permission.INTERNET"
      }
    ],
    "metaData": {
      "customizeData": [
        {
          "name": "hwc-theme",
          "value": "androidhwext:style/Theme.Emui.Light.NoTitleBar"
        }
      ]
    },


其中,reqPermissions是用于添加权限的,这里我们添加了ohos.permission.INTERNET网络权限。


还有默认应用创建都是有标题栏的,这里没有标题栏是因为博主设置了metaData样式,这里设置为无标题栏NoTitleBar。


本项目源代码文件下载:点击下载

相关文章
|
3月前
|
定位技术 UED
70. [HarmonyOS NEXT 实战案例九] 旅游景点网格布局(下)
在上一篇教程中,我们学习了如何使用GridRow和GridCol组件实现基本的旅游景点网格布局。本篇教程将在此基础上,深入探讨如何优化布局、添加交互功能,以及实现更多高级特性,打造一个功能完善的旅游景点应用。
85 1
|
3月前
|
容器
69.[HarmonyOS NEXT 实战案例九] 旅游景点网格布局(上)
本教程将详细讲解如何使用HarmonyOS NEXT中的GridRow和GridCol组件实现旅游景点网格布局。通过网格布局,我们可以以美观、规整的方式展示各种旅游景点信息,为用户提供良好的浏览体验。
80 1
|
3月前
|
UED
68.[HarmonyOS NEXT 实战案例八] 电影票务网格布局(下)
在上一篇教程中,我们学习了如何使用GridRow和GridCol组件实现基本的电影票务网格布局。本篇教程将在此基础上,深入探讨如何优化布局、添加交互功能,以及实现更多高级特性,打造一个功能完善的电影票务应用。
73 1
|
3月前
|
开发者 容器
67.[HarmonyOS NEXT 实战案例八] 电影票务网格布局(上)
在移动应用开发中,电影票务应用是一个常见的场景,用户可以通过应用查看正在热映的电影信息,并进行选座购票等操作。本教程将详细讲解如何使用HarmonyOS NEXT的GridRow和GridCol组件实现电影票务应用中的电影列表网格布局,帮助开发者掌握网格布局的基本用法和实现技巧。
87 1
|
开发工具 开发者
HarmonyOS初探02——开发第一个HarmonyOS应用
本节演示如何开发第一个HarmonyOS应用。
228 0
|
3月前
|
开发者
鸿蒙开发:资讯项目实战之项目初始化搭建
目前来说,我们的资讯项目只是往前迈了很小的一步,仅仅实现了项目创建,步虽小,但概念性的知识很多,这也是这个项目的初衷,让大家不仅仅可以掌握日常的技术开发,也能让大家理解实际的项目开发知识。
鸿蒙开发:资讯项目实战之项目初始化搭建
|
3月前
|
容器
HarmonyOS NEXT仓颉开发语言实战案例:外卖App
仓颉语言实战分享,教你如何用仓颉开发外卖App界面。内容包括页面布局、导航栏自定义、搜索框实现、列表模块构建等,附完整代码示例。轻松掌握Scroll、List等组件使用技巧,提升HarmonyOS应用开发能力。
|
3月前
|
缓存 JavaScript IDE
鸿蒙开发:基于最新API,如何实现组件化运行
手动只是让大家了解切换的原理,在实际开发中,可不推荐手动,下篇文章,我们将通过脚本或者插件,快速实现组件化模块之间的切换,实现独立运行,敬请期待!
115 0
鸿蒙开发:基于最新API,如何实现组件化运行
|
3月前
|
存储 IDE 定位技术
【HarmonyOS 5】鸿蒙组件&模板服务详解 - 助力高效开发的利器
在移动应用开发领域,效率与质量始终是开发者追求的核心目标。鸿蒙系统作为新兴的操作系统,为开发者提供了丰富且强大的开发资源,其中鸿蒙组件&模板服务更是成为开发者快速构建高质量应用的得力助手。
126 0
|
3月前
|
容器
HarmonyOS NEXT仓颉开发语言实战案例:健身App
本期分享一个健身App首页的布局实现,顶部采用Stack容器实现重叠背景与偏移效果,列表部分使用List结合Scroll实现可滚动内容。代码结构清晰,适合学习HarmonyOS布局技巧。