1 java android-video-player m3u android-studio exoplayer
构建项目时出现错误
error: cannot find symbol
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
^
symbol: class DefaultHttpDataSourceFactory
location: package com.google.android.exoplayer2.upstream
Run Code Online (Sandbox Code Playgroud)
无法导入 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'
}
Run Code Online (Sandbox Code Playgroud)
这是我的清单文件
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'
}
Run Code Online (Sandbox Code Playgroud)
这是exoplayer xml设计
<?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>
Run Code Online (Sandbox Code Playgroud)
这是我的 Java 代码,它插入了一个尝试播放 Exoplayer 的 M3U 链接。
<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>
Run Code Online (Sandbox Code Playgroud)
正如Exoplayer 发行说明中所述,DefaultHttpDataSourceFactory
已在版本 2.16.0 中删除,您应该使用DefaultHttpDataSource.Factory
它。
归档时间: |
|
查看次数: |
2977 次 |
最近记录: |