There is an error when building project

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 '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' } 

Here is my Manifest file

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="" xmlns: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> 

Here is exoplayer xml design

<FrameLayout xmlns:android="" xmlns:app="" xmlns: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> 

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("keyName"); String videouri = ""; 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 player.prepare(); // Start playing the video player.setPlayWhenReady(true); } catch (Exception e) { Log.e(TAG, "Error initializing player", e); } } @Override public void onBackPressed() { super.onBackPressed(); player.pause(); } @Override protected void onDestroy() { super.onDestroy(); player.release(); } } 
1

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.