Exoplayer源错误

4

在遵循开发人员指南中给出的示例后,我得到了以下结果:

05-23 16:25:22.002 11893-11942/com.app.videotest E/ExoPlayerImplInternal: Source error.

设置:
// 1. Create a default TrackSelector
        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

        // 2. Create the player
        SimpleExoPlayer player =
                ExoPlayerFactory.newSimpleInstance(this, trackSelector);

        // Bind the player to the view.
        PlayerView playerView = findViewById(R.id.player_view);
        playerView.setPlayer(player);

        // Produces DataSource instances through which media data is loaded.
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this,
                Util.getUserAgent(this, "yourApplicationName"), null);
        // This is the MediaSource representing the media to be played.
        MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
                .createMediaSource(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
        // Prepare the player with the source.
        player.prepare(videoSource);

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
    tools:context=".MainActivity">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/player_view"
        android:layout_width="200dp"
        android:layout_height="200dp" />
</android.support.constraint.ConstraintLayout>

完整日志:
05-23 16:25:18.919 11893-11893/? D/AppTracker: App Event: start
05-23 16:25:18.931 11893-11943/? D/OpenGLRenderer: HWUI GL Pipeline
05-23 16:25:18.946 11893-11945/? I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
05-23 16:25:18.951 11893-11945/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
05-23 16:25:18.982 11893-11943/? I/Adreno: QUALCOMM build                   : 08cdca0, I5f270ba9bc
    Build Date                       : 09/18/17
    OpenGL ES Shader Compiler Version: EV031.20.00.04
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.6.5.R1.08.00.00.312.025
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
05-23 16:25:18.982 11893-11943/? I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
05-23 16:25:18.985 11893-11943/? I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
05-23 16:25:18.990 11893-11943/? I/OpenGLRenderer: Initialized EGL, version 1.4
05-23 16:25:18.990 11893-11943/? D/OpenGLRenderer: Swap behavior 2
05-23 16:25:19.072 11893-11943/? I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
05-23 16:25:21.057 11893-11920/com.app.videotest I/zygote64: Do partial code cache collection, code=28KB, data=28KB
05-23 16:25:21.059 11893-11920/com.app.videotest I/zygote64: After code cache collection, code=28KB, data=28KB
    Increasing code cache capacity to 128KB
05-23 16:25:22.002 11893-11942/com.app.videotest E/ExoPlayerImplInternal: Source error.

这个URL肯定是有效的(而且我已经尝试过几个其他的)。我错过了什么?

更新:当我本地加载视频时,播放器确实可以工作。但这并没有解决我的问题。

尝试从logcat中粘贴更长的日志,也许上面有一些内容丢失了。 - jantursky
你是否连接到互联网?或者如果你可以下载资产中的视频文件并在本地加载它会怎样?我正在尝试解决这个问题,但是我没有你的全部源代码,所以有时候很难重现问题。 - jantursky
我确实有互联网连接。我将尝试本地加载视频并发布更新。<br>基本上,我发布的就是这些 - 我只有一个活动,其中包含ExoPlayer设置代码的onCreate方法,没有其他内容。 - Barazu
这个指南应该会帮助你 指南 - jantursky
你改了你的网络吗? - raxerz
显示剩余5条评论
1个回答

0

你使用的是Android 8吗?在我的情况下,我遇到了错误。

Caused by: java.io.IOException: Cleartext HTTP traffic to clips.vorwaerts-gmbh.de not permitted

然后,根据这个线程,你需要将你的清单文件(最简单的一个)修改为以下内容:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

请查看上面的链接以获取详细信息


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接