- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 .m3u8
文件播放加密视频。我将视频存储在 AWS 中并创建了 .ts 文件和主播放列表。 Aws 为我提供了该加密视频文件的一些 key 。现在我必须在 exoplayer 中使用这些键。我尝试使用 Aes128DataSource
和 DrmSessionManager
但没有成功。
关键类型是:
Encryption Key: ####################################################################
Encryption Key MD5: ################
Encryption Initialization Vector : #############
下面是我用来播放 hls 视频的代码。它可以流畅地播放视频,没有任何问题。我只需要知道在哪里以及如何使用 key 来播放加密视频。
String VIDEO_URL = "https://s3.amazonaws.com/######.###.##/videos/mobiletest/mobilemaster.m3u8";
//Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();
//Bis. Create a RenderFactory
RenderersFactory renderersFactory = new DefaultRenderersFactory(this);
//Create the player
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
simpleExoPlayerView = new SimpleExoPlayerView(this);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
//Set media controller
simpleExoPlayerView.setUseController(true);
simpleExoPlayerView.requestFocus();
// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);
// Set the media source
Uri mp4VideoUri = Uri.parse(VIDEO_URL);
//Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
//Produces DataSource instances through which media data is loaded.
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "PiwikVideoApp"), bandwidthMeterA);
//Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
//FOR LIVE STREAM LINK:
MediaSource videoSource = new HlsMediaSource(mp4VideoUri, dataSourceFactory, 1, null, null);
final MediaSource mediaSource = videoSource;
player.prepare(videoSource);
我已经使用 AWS Elastic Transcoder 加密了视频,并使用了 exoplayer 版本:2.6.0
最佳答案
我找到了解决办法。您需要做的技巧是创建您自己的自定义数据源。您需要创建一个扩展 HttpDataSource.BaseFactory 的类,并从 DefaultHttpDataSourceFactory 添加一些代码。我知道这听起来很疯狂,但我已经通过这种方式解决了。别担心,我将在此处粘贴该自定义类的全部代码。
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;
public class CustomDataSourcesFactory extends HttpDataSource.BaseFactory{
private final String userAgent;
private final @Nullable
TransferListener listener;
private final int connectTimeoutMillis;
private final int readTimeoutMillis;
private final boolean allowCrossProtocolRedirects;
/**
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param userAgent The User-Agent string that should be used.
*/
public CustomDataSourcesFactory(String userAgent) {
this(userAgent, null);
}
/**
* Constructs a DefaultHttpDataSourceFactory. Sets {@link
* DefaultHttpDataSource#DEFAULT_CONNECT_TIMEOUT_MILLIS} as the connection timeout, {@link
* DefaultHttpDataSource#DEFAULT_READ_TIMEOUT_MILLIS} as the read timeout and disables
* cross-protocol redirects.
*
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener.
*/
public CustomDataSourcesFactory(String userAgent, @Nullable TransferListener listener) {
this(userAgent, listener, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, false);
}
/**
* @param userAgent The User-Agent string that should be used.
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
* to HTTPS and vice versa) are enabled.
*/
public CustomDataSourcesFactory(
String userAgent,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this(
userAgent,
/* listener= */ null,
connectTimeoutMillis,
readTimeoutMillis,
allowCrossProtocolRedirects);
}
/**
* @param userAgent The User-Agent string that should be used.
* @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
* to HTTPS and vice versa) are enabled.
*/
public CustomDataSourcesFactory(
String userAgent,
@Nullable TransferListener listener,
int connectTimeoutMillis,
int readTimeoutMillis,
boolean allowCrossProtocolRedirects) {
this.userAgent = userAgent;
this.listener = listener;
this.connectTimeoutMillis = connectTimeoutMillis;
this.readTimeoutMillis = readTimeoutMillis;
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
}
@Override
protected HttpDataSource createDataSourceInternal(
HttpDataSource.RequestProperties defaultRequestProperties) {
DefaultHttpDataSource defaultHttpDataSource = new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects, defaultRequestProperties);
defaultHttpDataSource.setRequestProperty("your header", "your token");
return defaultHttpDataSource;
}}
您看到方法 createDataSourceInternal 了吗?我正在返回一个使用 header 键和 token defaultHttpDataSource.setRequestProperty("your header", "your token"); 初始化的 DefaultHttpDataSource 对象。因此,现在您的 exoplayer 将使用此 header 键和 token 值命中指控 URL,您的服务器端将检查这些 URL 以验证有效请求。您的 hls 播放列表 (.m3u8) 包含指控 URL。 Exoplayer 自动使用此 URL。您需要做的就是告诉玩家使用验证 key 。
这里又是您的自定义数据源的使用代码:
//ExoPlayer implementation
//Create a default TrackSelector
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();
//Bis. Create a RenderFactory
RenderersFactory renderersFactory = new DefaultRenderersFactory(this);
//Create the player
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
simpleExoPlayerView = new SimpleExoPlayerView(this);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
//Set media controller
simpleExoPlayerView.setUseController(true);
simpleExoPlayerView.requestFocus();
// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);
// Set the media source
Uri mp4VideoUri = Uri.parse(VIDEO_URL);
//DefaultHttpDataSource source = new DefaultHttpDataSource(Util.getUserAgent(this, "appAgent"), null);
//source.setRequestProperty("header", "user token");
//Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter();
//DefaultDataSourceFactory o = new DefaultDataSourceFactory(this, null, new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "appAgent"), bandwidthMeterA));
CustomDataSourcesFactory o = new CustomDataSourcesFactory("Exoplayer");
//Produces DataSource instances through which media data is loaded.
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "PiwikVideoApp"), bandwidthMeterA);
//Produces Extractor instances for parsing the media data.
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
//FOR LIVE STREAM LINK:
MediaSource videoSource = new HlsMediaSource(mp4VideoUri, o, 1, null, null);
final MediaSource mediaSource = videoSource;
player.prepare(videoSource);
这个问题对我来说太关键了,因为我找不到任何教程、资源或想法来解决这个问题。我写这篇文章是因为我不想让像我这样的其他菜鸟遭受这种痛苦。
如果你还不够清楚,欢迎在这里提问。我会进一步协助你。我还有服务器端代码,以便从 AWS 加密 key 生成解密 key 。
关于android - 使用加密 key 在 exoplayer 中播放加密的 hls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54128394/
我不确定我明白这里发生了什么。 请问有人可以解释一下吗? 我收到以下错误: Type of 'exoPlayer' doesn't match the type of the overridden v
我在尝试编译 exoplayer r1.5.2 存储库时遇到问题...。当我改用 com.google.android.exoplayer:exoplayer:r1.4.2 时没有问题。 编译代码如下
我有这个简单的 .m3u8 文件 #EXTM3U #EXT-X-VERSION:5 #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="English ste
为了避免应用程序中的任何 SCSS ,从后台线程使用 exoplayer 还是从主 ui 线程使用它更好? 注意:当我在主 ui 线程中创建一个 simpleExoPlayer 时: // 1. Cr
我有一个 exoplayer 我的第一个 Activity ,当我点击全屏按钮时,我打开一个新的 VideoActivity 全屏。我只发送我当前的位置并在该位置启动 VideoActivity。
我在 DemoPlayer 的基础上使用 Exoplayer。我想在 ExoPlayer.STATE_ENDED 被调度后在一些用户操作时从头开始重新启动/重播视频。 之后我尝试使用 seekTo(0
我在我的 android 应用程序中使用 exoplayer,在播放视频时我点击屏幕,带有 Controller 的显示不流畅,我想让它看起来流畅,就像淡入淡出..如何我可以这样做吗? 最佳答案 查看
我在 CardView 的 RecyclerView 中有一个 ex0player。 exoplayer 的高度需要根据包含的视频的高度以编程方式更改。此高度值以 像素 的形式从 API 调用返回。这
在 android 中有一个名为 的库。 Exoplayer 这与从给定 url 流式传输视频有关。 现在根据this firebase 不支持视频流,尽管您可以将 uri 从 url 传递到 vid
更新项目依赖项后,我在视频 android studio 应用程序中遇到这个 exoplayer not found 错误。 我不知道如何将旧的 Exoplayer 链接更新到 https://mvn
我在 android 中构建一个 expo 分离项目时遇到问题。当我构建项目时,控制台构建的输出显示:无法解析:com.google.android.exoplayer:exoplayer-smoot
情况:将我的 Android 项目从带有 VisualOn 的旧 Ooyala SDK 更新到带有 Exoplyer 的最新 Ooyala SDK。通过 Amazon Fire Stick 播放视频。
我制作了安卓音频应用程序。现在一些用户报告说,当他们在车内通过蓝牙连接设备时,应用程序没有响应媒体按钮(播放、暂停、下一步)。 同时,我用蓝牙扬声器测试了应用程序 - 播放/暂停按钮可按需工作。 车载
我希望在我的项目中实现 exoplayer。我已经成功实现了它,但是视频加载时间很慢。如何在 exoplayer 中实现或实现视频的快速加载?就像抖音一样——立即加载视频并开始播放 最佳答案 试试下面
遵循开发人员指南中给出的示例后,我得到以下信息: 05-23 16:25:22.002 11893-11942/com.app.videotest E/ExoPlayerImplInternal: S
我基于此 link 在我的应用程序中集成了 exoplayer . 我在 createCurrentContentIntent() 中添加了一个待处理的 Intent 。 return Pen
我正在阅读有关配置默认 exoplayer View 布局的教程: https://exoplayer.dev/ui-components.html 但是它不显示默认播放器布局的源代码 exo_pla
我想使用 PlayerView 在 exoplayer 中创建一个自定义时间栏: 不能被用户拖动,只能在视频中显示进度 更新:好的,所以我可以通过将 touch_target_height 设置为 0
07-03 18:51:01.600 16188-16266/? E/ExoPlayerImplInternal﹕ Internal runtime error. java.lang.Ill
使用 ExoPlayer我正在尝试同时播放两个音轨。 我的想法是创建两个 MediaSource , 并使用 MergingMediaSource 在它们之间“组合” . 这就是我所做的: U
我是一名优秀的程序员,十分优秀!