exoplayer 示例上的自定义 UI

2024-01-07

** 我真的需要帮助,如果你什么都不知道,请不要给我负面评价:|如果有什么困扰你评论**

我想在 Exoplayer 中为我的播放器编写自定义 UI(更改暂停播放按钮或添加新按钮,例如播放器速度下一个等)。

我使用 github 上的 Exoplayer 示例,在将代码添加到我的原始项目之前,我想在官方示例上测试自定义 UI。

我在 Stackoverflow 和 tuts+ 中阅读了有关自定义 UI 的页面,但我真的很困惑!

为什么更改某些按钮图像或更改它们的位置一定如此困难:)我该如何处理这个问题?

EDIT

这是样本https://github.com/google/ExoPlayer/tree/master/demo https://github.com/google/ExoPlayer/tree/master/demo

我读了这两篇文章:

http://www.brightec.co.uk/ideas/custom-android-media-controller http://www.brightec.co.uk/ideas/custom-android-media-controller

http://code.tutsplus.com/tutorials/create-a-music-player-on-android-user-controls--mobile-22787 http://code.tutsplus.com/tutorials/create-a-music-player-on-android-user-controls--mobile-22787

根据这个link http://brightec.co.uk/ideas/custom-android-media-controller“您可以从 Android 中包含的 MediaController 类开始,而不是从头开始编写自己的媒体控制器”,我问这个问题是因为我无法在 exoplayer 库上执行此步骤,并且教程是为默认媒体播放器编写的


自定义 ExoPlayer 的 UI 非常简单。如果您查看 ExoPlayer 源代码,布局 res 目录包含该文件exo_player_control_view.xml指向(包括)另一个布局 -exo_playback_control_view.

  1. 复制布局资源的内容 -exo_playback_control_view.xml
  2. 使用您选择的任何名称创建布局资源文件 - 例如:custom_exo_playback_control_view.xml。将复制的内容粘贴到新的xml中
  3. 根据需要对 UI 小部件进行任何更改。不要更改任何小部件/控件的 Id 属性。
  4. 将自定义 exoPlayer UI 资源指向包含以下内容的布局文件:PlayerView.

这里是custom_exo_controller_view我根据原始文件创建了 xml。我想要为播放器控件使用不同的背景颜色以及不同的按钮和进度视图颜色:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@drawable/attachment_document_desc_bg"
    android:layoutDirection="ltr"
    android:orientation="vertical"
    android:paddingStart="20dp"
    android:paddingEnd="20dp"
    tools:targetApi="28">

  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:orientation="horizontal"
      android:paddingTop="4dp">

    <ImageButton
        android:id="@id/exo_prev"
        style="@style/ExoMediaButton.Previous"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_rew"
        style="@style/ExoMediaButton.Rewind"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_shuffle"
        style="@style/ExoMediaButton.Shuffle"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_repeat_toggle"
        style="@style/ExoMediaButton"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_play"
        style="@style/ExoMediaButton.Play"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_pause"
        style="@style/ExoMediaButton.Pause"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_ffwd"
        style="@style/ExoMediaButton.FastForward"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_next"
        style="@style/ExoMediaButton.Next"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

    <ImageButton
        android:id="@id/exo_vr"
        style="@style/ExoMediaButton.VR"
        android:tint="@color/colorPrimaryDark"
        android:tintMode="src_in" />

  </LinearLayout>

  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="4dp"
      android:gravity="center_vertical"
      android:orientation="horizontal">

    <TextView
        android:id="@id/exo_position"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:includeFontPadding="false"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:textColor="#ff323232"
        android:textSize="14sp"
        android:textStyle="bold" />

    <com.google.android.exoplayer2.ui.DefaultTimeBar
        android:id="@id/exo_progress"
        android:layout_width="0dp"
        android:layout_height="26dp"
        android:layout_weight="1"
        app:played_color="@color/colorPrimaryDark"
        app:unplayed_color="@color/gray" />

    <TextView
        android:id="@id/exo_duration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:includeFontPadding="false"
        android:paddingLeft="4dp"
        android:paddingRight="4dp"
        android:textColor="#ff323232"
        android:textSize="14sp"
        android:textStyle="bold" />

  </LinearLayout>

</LinearLayout>

下面是我用于播放器的代码。注意,xml 属性app:controller_layout_id指向上面定义的自定义控制器视图。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp">

  <com.google.android.exoplayer2.ui.PlayerView
      android:id="@+id/video_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      app:auto_show="true"
      app:controller_layout_id="@layout/custom_exo_controller_view"
      app:fastforward_increment="10000"
      app:repeat_toggle_modes="none"
      app:resize_mode="fixed_width"
      app:rewind_increment="10000"
      app:surface_type="surface_view"
      app:use_controller="true" />

</FrameLayout>

这应该会得到你想要的用户界面。

您可以根据需要在自定义控制器和代码中添加额外的控件,使用以下命令查找控件findViewById()并编写事件监听器等。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

exoplayer 示例上的自定义 UI 的相关文章

  • 通过数据绑定将字符串传递到包含的布局不起作用

    我正在尝试使用 Android 数据绑定功能将一个简单的字符串从我的主布局传递到布局 它编译得很好 但传递给包含的值实际上并未传递 即 它没有出现在我的布局中
  • 已发布的 Flutter 应用程序在启动时崩溃

    编辑 此问题的解决方案是将您的 flutter 版本升级到较新的 dev 版本 then 1 7 0 您还可以上传单独的 APK 版本 但我个人不喜欢这个选项 请确保您没有从 flutter github 开发存储库下载 错误的构建 因为那
  • 如何在出现“无法解析放置符号”错误时向哈希图添加键和值

    我正在与安卓工作室 https en wikipedia org wiki Android Studio1 4 1 我刚刚创建了一个 Hashmap 并正在遵循有关如何填充和操作它的教程 Java 语言 但是 我收到 无法解析符号放置 错误
  • AppCompat v21 工具栏更改徽标大小

    我正在从以前的操作栏迁移到 appcompat v21 中的新工具栏功能 我仍然想将徽标保留在操作栏 工具栏 的左上角 为此 我在布局中添加了支持工具栏 并为其创建了一个新的工具栏 app theme style NewToolBarSty
  • Android Studio:lambda 不起作用[重复]

    这个问题在这里已经有答案了 当尝试使用 lambda 表达式时 我遇到了一些 Gradle 构建错误 错误 41 100 错误 source 1 7 不支持 lambda 表达式 使用 source 8 或更高版本来启用 lambda 表达
  • 如何将 EditText 传递给另一个活动?

    Intent intent new Intent this Name class intent putExtra key et getText toString startActivity intent Intent intent getI
  • Android Lollipop prepareAsync() 需要很长时间才能返回

    在 Samsung Galaxy Note 4 上的 Android Lollipop 几周前刚刚从 4 4 4 更新 上 prepareAsync 几乎需要 20 秒来加载实时流 在 4 4 4 上 只需要 2 3 秒 并且没有错误 见下
  • 按钮未显示在屏幕上

    我创建了一个应用程序 其中显示带有图像和文本的列表视图 我在页面末尾添加按钮 但这没有显示在屏幕上 我是 Android 新手 我该如何解决这个问题 这是我的 UI XML 代码
  • 如何将画廊意图中的“打开”更改为“完成”?

    我使用以下意图打开画廊来选择多个图像和视频 Intent intent new Intent intent setType image video intent putExtra Intent EXTRA ALLOW MULTIPLE tr
  • 访问角落里的存储

    我能找到的与文件存储有关的最接近文档的是这个帖子 http nookdeveloper zendesk com entries 20257971 updated what are the size constraints on my app
  • 如何在 Firebase 远程配置中从 JSON 获取值

    我是 Android 应用开发和 Firebase 的新手 我想知道如何获取存储在 Firebase 远程配置中的 JSONArray 文件中的值 String 和 Int 我使用 Firebase Remote Config 的最终目标是
  • Android ListView setSelection() 似乎不起作用

    我有一个ListActivity实现onListItemClick 并调用doSomething 类的功能 后者包含l setSelection position where l is the ListView object 现在有一个on
  • Google 移动广告和 Kindle Fire

    我最近用 Google 移动广告替换了 AdMob 库 对此我有一个疑问 广告会出现在 Amazon Kindle Fire 设备上吗 我问这个是因为我知道 Google 移动广告依赖于 Google Play 服务 所以我有点困惑 Goo
  • Android 改变 ImageView / Bitmap 的颜色

    我需要找到一种方法来改变 Android 中位图的颜色 我需要在我的应用程序中平滑地替换 更改椭圆形图像的颜色 具体取决于int价值 我需要类似的东西myValue 5比改变我的图像的颜色RED and if myValue 322将颜色更
  • jar 中的 apklib 有什么优点?

    我正在关注这个问题 https stackoverflow com questions 6059502 whats the difference between apklib and jar files但它并没有完全回答我的问题 jar 中
  • Ionic Facebook Api 无效密钥哈希

    我无法让我的应用程序允许 Facebook 登录 每次用户尝试登录 Facebook 并使用他们的 FB 验证我的应用程序时 都会出现以下错误 无效的密钥哈希 它们的密钥哈希 xxxxxxxxxx 与任何存储的密钥哈希不匹配 配置您的应用程
  • “无法实例化活动”错误

    我的一个 Android 应用程序拥有大约 100 000 个用户 每周大约 10 次 我会通过 Google 的市场工具向我报告以下异常情况 java lang RuntimeException Unable to instantiate
  • 更改Android菜单的背景颜色[重复]

    这个问题在这里已经有答案了 我正在尝试将标准浅灰色更改为浅绿色 似乎没有一个简单的方法可以做到这一点 例如 通过 Android 主题 但我找到了一个解决方法 如本页所述 http tinyurl com 342dgn3 http tiny
  • android:layout_alignParentBottom 在没有显式布局高度作为 ListView 中的行的情况下使用时会被忽略

    当我使用RelativeLayout与任一fill parent or wrap content作为高度和一个指定的元素 android layout alignParentBottom true 它被忽略并在顶部对齐 设置高度Relati
  • Android 中的 Google Places API - 适用于个人用户的 API_KEY

    我已经浏览了与在 Android 应用程序中使用 Places API 相关的 Android 文档和其他博客 到处都建议使用 API KEY 来调用 REST 服务 API KEY 在整个项目 应用程序中都是相同的 每天的请求数限制为 1

随机推荐

  • WPF:TreeViewItem 绑定到 ICommand

    我正忙于在 WPF 中创建我的第一个 MVVM 应用程序 基本上我遇到的问题是我有一个 TreeView System Windows Controls TreeView 我已将其放置在 WPF 窗口上 我决定将绑定到 CommandVie
  • 更改表类似

    是否可以在 ALTER TABLE 上使用类似于 MySQL 中的 CREATE TABLE 的 LIKE 语句 例如 创建表 db tbl1 像 db tbl2 这会克隆数据库表的结构 我想更改具有相同列的现有表 但要选择另一个表的主键
  • 如何设置字符串的颜色[重复]

    这个问题在这里已经有答案了 有谁知道我将如何设置将使用打印的字符串的颜色System out 这是我目前拥有的代码 System out println TEXT THAT NEEDS TO BE A DIFFERENT COLOR 安慰
  • 将 pandas 数据框中的多列拆分为行

    我有一个 pandas 数据框 如下所示 ticker account value date aa assets 100 200 20121231 20131231 bb liabilities 50 150 20141231 201312
  • 正则表达式的局限性? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Typescript 创建模块

    我想为我们的库创建模块 所以每次我们调用时 我们都可以使用import Api Map from ourlibrary 目前我正在使用以下 import Api from Library Api import MapPage from ma
  • 非常非常大的实体组的交易

    我正在尝试设计一个可以容纳大量数据的数据模型 有大量数据经验的人对此有什么反馈吗 即 example only not meant to compile public class TransactionAccount private lon
  • 如何对每小时时间序列重新采样以在特定时间开始并在 24 小时后结束

    我想从一天中的特定时间开始 在我的情况下 将从 2020 年 2 月 1 日 06 UTC 开始 对我的数据框进行重新采样 包括每小时降水量值 频率为 24 小时 2020 02 01 每小时数据帧图像 I tried df df resa
  • PHP,如何重定向/转发带标头和正文的 HTTP 请求?

    我有一个 PHP 页面 main php 位于服务器 1 上 我在服务器 2 上有一个 PHP 页面 main php 同一页面 不同的代码 main php 是一个 Web 服务 我想转发对服务器 1 服务器 2 发出的完整 HTTP 请
  • Angular - 生成的表格单元格上的(单击)事件

    我一直在尝试在动态生成的表格中的单元格上添加 单击 事件 HTMLtoAdd any Input roles string ngOnInit let alphabet A B C D E F G H I J K L M N O P Q R
  • 如何用类创建div

    我正在尝试创建一个 div 并给他上一堂课 但它不起作用 有人可以帮助我吗 document ready function input type checkbox each function this after div div class
  • Vue.js - 如何将 props 传递给孙子

    我有以下应用程序结构 RegistrationView holds the data logic like get post RegistrationForm holds the form Registration Radio Compon
  • 使用 JSch 跳过 Kerberos 身份验证提示 [重复]

    这个问题在这里已经有答案了 我正在使用Connect 方法中的Ssh下面的 Java 类用于使用 SSH JSch 连接到服务器并在服务器中运行命令 问题是运行时Connect 服务器提示以下消息 Kerberos username Ker
  • clojure 中惯用的文件锁定?

    我有一组来自队列的 future 处理作业 涉及写入文件 确保一次只有一个未来访问特定文件的惯用方法是什么 使用代理而不是锁来确保这一点怎么样 我认为使用代理来保护共享的可变状态 无论它是在内存中还是在磁盘上 在 clojure 中比使用锁
  • 活动标题语言有问题

    我的应用程序中有两种语言 值 strings xml and 值 ru strings xml当我以编程方式更改语言时 所有字符串都会翻译 但活动标题不变 我在所有活动中使用 SharedPreferences prefs Preferen
  • 如何对列表使用二分查找

    让我们从 List BinarySearch 的重载开始 public int BinarySearch T item IComparer
  • 无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc

    我正在尝试使用谷歌的语音API https github com GoogleCloudPlatform android docs samples tree master speech Speech在Android项目中 示例项目有效 我在
  • Kendo Grid:工具栏模板问题

    我有一个列出道路信息的网格 并且需要一个工具栏模板 该模板允许我通过从 DropDownList 中选择特许权来过滤道路 像这样的东西 http demos telerik com aspnet mvc grid toolbar templ
  • 如何在服务器上运行java程序?

    我制作了一个 java 应用程序 将 csv 文件中的数据存储到 MySql 数据库中 现在我的客户希望它将此应用程序上传到他的网络空间 他为其网站占用的网络空间 以便他可以在该服务器上运行该程序 我用过FileZilla软件将程序上传到他
  • exoplayer 示例上的自定义 UI

    我真的需要帮助 如果你什么都不知道 请不要给我负面评价 如果有什么困扰你评论 我想在 Exoplayer 中为我的播放器编写自定义 UI 更改暂停播放按钮或添加新按钮 例如播放器速度下一个等 我使用 github 上的 Exoplayer