error: 无法找到符号 import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory

huangapple go评论56阅读模式
英文:

error: cannot find symbol import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory

问题

在构建项目时出现了错误:

error: cannot find symbol
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
^
symbol:   class DefaultHttpDataSourceFactory
location: package com.google.android.exoplayer2.upstream

无法导入DefaultHttpDataSourceFactory类,但已添加了所有依赖项。这个问题的解决方案是什么?

以下是我的Gradle依赖项:

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.testiptv'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.testiptv"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    implementation 'com.android.volley:volley:1.2.1'

    implementation 'com.google.android.exoplayer:exoplayer:2.18.4'
//    implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.4'
//    implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer:2.18.4'
  //  implementation 'com.google.android.exoplayer:exoplayer-core:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer:2.11.8'


    implementation 'com.google.android.exoplayer:exoplayer-core:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.18.4'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.4'
}

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:usesCleartextTraffic="true"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.TestIPTV"
        tools:targetApi="31">
        <activity
            android:name=".videoplayer"
            android:usesCleartextTraffic="true"
            android:screenOrientation="sensor"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

这是ExoPlayer的XML设计:

<FrameLayout 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:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".videoplayer"
    android:keepScreenOn="true">

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/player_view"
    app:show_subtitle_button="false"
    app:hide_on_touch="true"
    app:use_controller="true"
    app:controller_layout_id="@layout/custom_exo_view"
    app:show_vr_button="false"
    app:resize_mode="fill"
    app:show_shuffle_button="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</FrameLayout>

这是我插入M3U链接并尝试播放ExoPlayer的Java代码:

package com.example.testiptv;

import static android.content.ContentValues.TAG;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;

public class videoplayer extends AppCompatActivity {

    protected PlayerView playerView;

    SimpleExoPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_videoplayer);

        playerView = findViewById(R.id.player_view);
        playvideo();
    }

    private void playvideo() {
        //String videouri = getIntent().getStringExtra("keyName");
        String videouri = "https://stmv.video.expressolider.com.br/ghostv/ghostv/playlist.m3u8";

        try {
            Uri uri = Uri.parse(videouri);
            player = new SimpleExoPlayer(videoplayer.this);

            playerView.setPlayer(player);

            // Create an HTTPS data source factory
            DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
                    "exoplayer-codelab",
                    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                    DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                    true /* allowCrossProtocolRedirects */,
                    DefaultHttpDataSourceFactory.DEFAULT_SSL_SOCKET_FACTORY);

            // Create a media source using the data source factory
            MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
            Log.d(TAG, "Media source created: " + (mediaSource != null));

            // Set the media source for the player
            player.setMediaSource(mediaSource);

            // Prepare the player


<details>
<summary>英文:</summary>

There is an error when building project

```none
error: cannot find symbol
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
^
symbol:   class DefaultHttpDataSourceFactory
location: package com.google.android.exoplayer2.upstream

Can not import the DefaultHttpDataSourceFactory class. but all dependencies are added. What is this problem's solution?

Here is my Gradle dependencies

plugins {
    id &#39;com.android.application&#39;
}

android {
    namespace &#39;com.example.testiptv&#39;
    compileSdk 33

    defaultConfig {
        applicationId &quot;com.example.testiptv&quot;
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName &quot;1.0&quot;

        testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation &#39;androidx.appcompat:appcompat:1.6.1&#39;
    implementation &#39;com.google.android.material:material:1.8.0&#39;
    implementation &#39;androidx.constraintlayout:constraintlayout:2.1.4&#39;
    testImplementation &#39;junit:junit:4.13.2&#39;
    androidTestImplementation &#39;androidx.test.ext:junit:1.1.5&#39;
    androidTestImplementation &#39;androidx.test.espresso:espresso-core:3.5.1&#39;

    implementation &#39;com.android.volley:volley:1.2.1&#39;

    implementation &#39;com.google.android.exoplayer:exoplayer:2.18.4&#39;
//    implementation &#39;com.google.android.exoplayer:exoplayer-ui:2.18.4&#39;
//    implementation &#39;com.google.android.exoplayer:exoplayer-hls:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer:2.18.4&#39;
  //  implementation &#39;com.google.android.exoplayer:exoplayer-core:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer:2.11.8&#39;


    implementation &#39;com.google.android.exoplayer:exoplayer-core:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer-dash:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer-hls:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer-smoothstreaming:2.18.4&#39;
    implementation &#39;com.google.android.exoplayer:exoplayer-ui:2.18.4&#39;
}

Here is my Manifest file

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;

    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
    &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;

    &lt;application
        android:usesCleartextTraffic=&quot;true&quot;

        android:allowBackup=&quot;true&quot;
        android:dataExtractionRules=&quot;@xml/data_extraction_rules&quot;
        android:fullBackupContent=&quot;@xml/backup_rules&quot;
        android:icon=&quot;@mipmap/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot;
        android:supportsRtl=&quot;true&quot;
        android:theme=&quot;@style/Theme.TestIPTV&quot;
        tools:targetApi=&quot;31&quot;&gt;
        &lt;activity
            android:name=&quot;.videoplayer&quot;
            android:usesCleartextTraffic=&quot;true&quot;
            android:screenOrientation=&quot;sensor&quot;
            android:exported=&quot;false&quot; /&gt;
        &lt;activity
            android:name=&quot;.MainActivity&quot;
            android:exported=&quot;true&quot;&gt;

            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;

                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;

    &lt;/application&gt;

&lt;/manifest&gt;

Here is exoplayer xml design

&lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:id=&quot;@+id/root&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:context=&quot;.videoplayer&quot;
    android:keepScreenOn=&quot;true&quot;&gt;

&lt;com.google.android.exoplayer2.ui.PlayerView
    android:id=&quot;@+id/player_view&quot;
    app:show_subtitle_button=&quot;false&quot;
    app:hide_on_touch=&quot;true&quot;
    app:use_controller=&quot;true&quot;
    app:controller_layout_id=&quot;@layout/custom_exo_view&quot;
    app:show_vr_button=&quot;false&quot;
    app:resize_mode=&quot;fill&quot;
    app:show_shuffle_button=&quot;false&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot; /&gt;

&lt;/FrameLayout&gt;

Here is my Java code that inserts a M3U link that is trying to play Exoplayer.

package com.example.testiptv;

import static android.content.ContentValues.TAG;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;

public class videoplayer extends AppCompatActivity {

    protected PlayerView playerView;

    SimpleExoPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_videoplayer);

        playerView = findViewById(R.id.player_view);
        playvideo();
    }

    private void playvideo() {
        //String videouri = getIntent().getStringExtra(&quot;keyName&quot;);
        String videouri = &quot;https://stmv.video.expressolider.com.br/ghostv/ghostv/playlist.m3u8&quot;;

        try {
            Uri uri = Uri.parse(videouri);
            player = new SimpleExoPlayer(videoplayer.this);

            playerView.setPlayer(player);

            // Create an HTTPS data source factory
            DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
                    &quot;exoplayer-codelab&quot;,
                    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                    DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
                    true /* allowCrossProtocolRedirects */,
                    DefaultHttpDataSourceFactory.DEFAULT_SSL_SOCKET_FACTORY);

            // Create a media source using the data source factory
            MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
            Log.d(TAG, &quot;Media source created: &quot; + (mediaSource != null));

            // Set the media source for the player
            player.setMediaSource(mediaSource);

            // Prepare the player
            player.prepare();

            // Start playing the video
            player.setPlayWhenReady(true);

        } catch (Exception e) {
            Log.e(TAG, &quot;Error initializing player&quot;, e);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        player.pause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        player.release();
    }
}

答案1

得分: 2

如在ExoPlayer发布说明中提到,DefaultHttpDataSourceFactory在版本2.16.0中已移除,您应该改用DefaultHttpDataSource.Factory

英文:

As mentioned in Exoplayer release notes, DefaultHttpDataSourceFactory is removed in version 2.16.0 and you should use DefaultHttpDataSource.Factory instead.

huangapple
  • 本文由 发表于 2023年3月9日 17:51:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定