【问题标题】:com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException:响应代码:404
【发布时间】:2019-11-28 08:38:29
【问题描述】:

好的,我将通过 ExoPlayer 播放 YouTube video,方法是使用 Javascript 接口调用播放过程...

问题是,当我尝试使用 ExoPlayer 打开视频时,它确实尝试打开链接而不是没有播放,当我看到 Logcat 时,我得到了错误

E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:300)
        at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
        at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.java:102)
        at com.google.android.exoplayer2.upstream.DataSourceInputStream.open(DataSourceInputStream.java:65)
        at com.google.android.exoplayer2.upstream.ParsingLoadable.load(ParsingLoadable.java:156)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)

我尝试将 final 添加到包含视频 URL 的字符串中,就像 here 中的答案所建议的那样,但仍然得到相同的错误

所以,我尝试向上滚动 Logcat,发现 SSL 错误

SSL_connect:error exit in 3RSH_A SSLv3 read server hello A

然后我尝试使用this中的解决方案,但仍然遇到同样的错误

我的代码

ExoPlayer.java

public class ExoPlayer extends AppCompatActivity{
    private PlayerView playerView;
    private SimpleExoPlayer simpleExoPlayer;
    public static String url;
    public Context context;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_player);

        final String video = getIntent().getStringExtra("video");

        iniExoPlayer(video);
    }


    public void iniExoPlayer(String url){
        Log.d("owo",url);
        simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this);
        playerView = findViewById(R.id.video_player);
        playerView.setPlayer(simpleExoPlayer);

        //#Default Data Source use this
        DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "app-name"));
        MediaSource videoSource = new SsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url));
            simpleExoPlayer.prepare(videoSource);
            simpleExoPlayer.setPlayWhenReady(true);
         }

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <base includeSubdomains="true">MainUrl</base>
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>

</network-security-config>

这是我的Logcat

【问题讨论】:

  • 你找到解决办法了吗?
  • 不,我将视频播放器转换为 VLC

标签: java android ssl webview


【解决方案1】:

检查您的 URL 链接。因为该链接上没有视频

我通过更改网址解决了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 2015-08-10
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多