Migración de ExoPlayer 2.x a Media3 1.5.0 (v10.1.0)
## Cambios realizados - Migración completa de ExoPlayer 2.x a AndroidX Media3 1.5.0 - Actualización de dependencias: media3-exoplayer, media3-ui, media3-session, etc. - Actualización de imports en PlayerActivity.java - Actualización del namespace de PlayerView en activity_player.xml - Incremento de versionCode a 100100 y versionName a 10.1.0 - Actualización de compileSdk y targetSdk a 35 para compatibilidad - Soporte mejorado para Android TV/Leanback - Preparación para MediaSession integrado ## Testing - Compilación exitosa sin errores - APK generado: StreamPlayer-v10.1.0-Media3-debug.apk 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
305
todo.md
Normal file
305
todo.md
Normal file
@@ -0,0 +1,305 @@
|
||||
# Migracion de ExoPlayer 2.x a Media3
|
||||
|
||||
## Objetivo
|
||||
Migrar StreamPlayer de ExoPlayer 2.18.7 a AndroidX Media3 1.5.0 para obtener:
|
||||
- Soporte activo y actualizaciones de seguridad
|
||||
- Mejor integracion con Android TV/Leanback
|
||||
- MediaSession integrado para controles del sistema
|
||||
|
||||
## Version objetivo
|
||||
- **Media3**: 1.5.0
|
||||
- **Nueva version app**: 10.1.0 (versionCode: 100100)
|
||||
|
||||
---
|
||||
|
||||
# PASO 1: Actualizar build.gradle
|
||||
|
||||
## Archivo: `app/build.gradle`
|
||||
|
||||
### 1.1 Cambiar dependencias
|
||||
|
||||
**ELIMINAR estas lineas (51-55):**
|
||||
```gradle
|
||||
// ExoPlayer para reproducción de video
|
||||
implementation 'com.google.android.exoplayer:exoplayer:2.18.7'
|
||||
implementation 'com.google.android.exoplayer:extension-okhttp:2.18.7'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
|
||||
```
|
||||
|
||||
**AGREGAR estas lineas en su lugar:**
|
||||
```gradle
|
||||
// Media3 para reproduccion de video (Android TV optimizado)
|
||||
implementation 'androidx.media3:media3-exoplayer:1.5.0'
|
||||
implementation 'androidx.media3:media3-exoplayer-hls:1.5.0'
|
||||
implementation 'androidx.media3:media3-datasource-okhttp:1.5.0'
|
||||
implementation 'androidx.media3:media3-ui:1.5.0'
|
||||
implementation 'androidx.media3:media3-ui-leanback:1.5.0'
|
||||
implementation 'androidx.media3:media3-session:1.5.0'
|
||||
|
||||
// OkHttp con DNS over HTTPS
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
|
||||
```
|
||||
|
||||
### 1.2 Actualizar version
|
||||
|
||||
**CAMBIAR (lineas 11-12):**
|
||||
```gradle
|
||||
versionCode 100100
|
||||
versionName "10.1.0"
|
||||
```
|
||||
|
||||
### 1.3 Actualizar compileSdk (opcional pero recomendado)
|
||||
|
||||
**CAMBIAR (linea 5):**
|
||||
```gradle
|
||||
compileSdk 34
|
||||
```
|
||||
|
||||
**CAMBIAR (linea 10):**
|
||||
```gradle
|
||||
targetSdk 34
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# PASO 2: Actualizar PlayerActivity.java
|
||||
|
||||
## Archivo: `app/src/main/java/com/streamplayer/PlayerActivity.java`
|
||||
|
||||
### 2.1 Cambiar TODOS los imports
|
||||
|
||||
**ELIMINAR estos imports (lineas 14-24):**
|
||||
```java
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource;
|
||||
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.util.Util;
|
||||
```
|
||||
|
||||
**AGREGAR estos imports en su lugar:**
|
||||
```java
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.PlaybackException;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.exoplayer.DefaultRenderersFactory;
|
||||
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector;
|
||||
import androidx.media3.datasource.okhttp.OkHttpDataSource;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.hls.HlsMediaSource;
|
||||
import androidx.media3.ui.PlayerView;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
```
|
||||
|
||||
### 2.2 Agregar anotacion @OptIn a la clase
|
||||
|
||||
**ANTES de la declaracion de clase (linea 37), AGREGAR:**
|
||||
```java
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public class PlayerActivity extends AppCompatActivity {
|
||||
```
|
||||
|
||||
Esto es necesario porque algunas APIs de Media3 estan marcadas como "unstable" pero son perfectamente funcionales.
|
||||
|
||||
### 2.3 Cambiar metodo buildMediaSource
|
||||
|
||||
**El metodo buildMediaSource (lineas 188-200) debe quedar asi:**
|
||||
|
||||
```java
|
||||
private MediaSource buildMediaSource(MediaItem mediaItem) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Referer", channelUrl);
|
||||
headers.put("Origin", "https://streamtpcloud.com");
|
||||
headers.put("Accept", "*/*");
|
||||
headers.put("Connection", "keep-alive");
|
||||
|
||||
String userAgent = Util.getUserAgent(this, "StreamPlayer");
|
||||
|
||||
OkHttpDataSource.Factory factory = new OkHttpDataSource.Factory(provideOkHttpClient())
|
||||
.setUserAgent(userAgent)
|
||||
.setDefaultRequestProperties(headers);
|
||||
return new HlsMediaSource.Factory(factory).createMediaSource(mediaItem);
|
||||
}
|
||||
```
|
||||
|
||||
**NOTA**: El codigo es casi identico, solo cambian los imports. Verificar que compile.
|
||||
|
||||
### 2.4 Verificar compatibilidad de DefaultTrackSelector
|
||||
|
||||
El metodo `setForceHighestSupportedBitrate(true)` sigue existiendo en Media3, no requiere cambios.
|
||||
|
||||
---
|
||||
|
||||
# PASO 3: Actualizar activity_player.xml
|
||||
|
||||
## Archivo: `app/src/main/res/layout/activity_player.xml`
|
||||
|
||||
### 3.1 Cambiar el namespace del PlayerView
|
||||
|
||||
**CAMBIAR (linea 10):**
|
||||
```xml
|
||||
<com.google.android.exoplayer2.ui.PlayerView
|
||||
```
|
||||
|
||||
**POR:**
|
||||
```xml
|
||||
<androidx.media3.ui.PlayerView
|
||||
```
|
||||
|
||||
El resto de atributos (`app:resize_mode`, `app:use_controller`) siguen funcionando igual.
|
||||
|
||||
---
|
||||
|
||||
# PASO 4: Sincronizar y Compilar
|
||||
|
||||
### 4.1 Sync Gradle
|
||||
Ejecutar:
|
||||
```bash
|
||||
./gradlew --refresh-dependencies
|
||||
```
|
||||
|
||||
### 4.2 Limpiar y compilar
|
||||
```bash
|
||||
./gradlew clean assembleDebug
|
||||
```
|
||||
|
||||
### 4.3 Verificar errores
|
||||
Si hay errores de compilacion, revisar:
|
||||
1. Que todos los imports esten actualizados
|
||||
2. Que la anotacion `@OptIn` este presente
|
||||
3. Que el namespace en XML este correcto
|
||||
|
||||
---
|
||||
|
||||
# PASO 5: Testing
|
||||
|
||||
### 5.1 Probar en Android TV
|
||||
- Instalar APK en dispositivo Android TV
|
||||
- Verificar que los canales cargan correctamente
|
||||
- Verificar que la calidad se mantiene en maxima
|
||||
- Verificar navegacion con D-pad
|
||||
|
||||
### 5.2 Verificar funcionalidades
|
||||
- [ ] Reproduccion de streams HLS
|
||||
- [ ] Overlay de controles
|
||||
- [ ] Boton "Elegir otro"
|
||||
- [ ] Manejo de errores
|
||||
- [ ] Reconexion tras perdida de conexion
|
||||
|
||||
---
|
||||
|
||||
# PASO 6: Commit y Release
|
||||
|
||||
### 6.1 Copiar APK
|
||||
```bash
|
||||
cp app/build/outputs/apk/debug/app-debug.apk ./StreamPlayer-v10.1.0-debug.apk
|
||||
```
|
||||
|
||||
### 6.2 Commit
|
||||
```bash
|
||||
git add -A
|
||||
git commit -m "Migracion de ExoPlayer 2.x a Media3 1.5.0 (v10.1.0)"
|
||||
git tag v10.1.0
|
||||
git push origin main
|
||||
git push origin v10.1.0
|
||||
```
|
||||
|
||||
### 6.3 Crear release en Gitea
|
||||
```bash
|
||||
curl -s -u renato97:wlillidan1 -X POST \
|
||||
"https://gitea.cbcren.online/api/v1/repos/renato97/app/releases" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"tag_name": "v10.1.0",
|
||||
"name": "StreamPlayer v10.1.0 - Media3",
|
||||
"body": "## Cambios\n- Migracion completa de ExoPlayer 2.x a AndroidX Media3 1.5.0\n- Mejor soporte para Android TV\n- Actualizaciones de seguridad y rendimiento",
|
||||
"prerelease": false
|
||||
}'
|
||||
```
|
||||
|
||||
### 6.4 Subir APK
|
||||
```bash
|
||||
# Reemplazar {RELEASE_ID} con el ID devuelto
|
||||
curl -s -u renato97:wlillidan1 -X POST \
|
||||
"https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/{RELEASE_ID}/assets?name=StreamPlayer-v10.1.0.apk" \
|
||||
--data-binary @./StreamPlayer-v10.1.0-debug.apk \
|
||||
-H "Content-Type: application/vnd.android.package-archive"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Tabla de Mapeo de Imports
|
||||
|
||||
| ExoPlayer 2.x | Media3 |
|
||||
|---------------|--------|
|
||||
| `com.google.android.exoplayer2.ExoPlayer` | `androidx.media3.exoplayer.ExoPlayer` |
|
||||
| `com.google.android.exoplayer2.MediaItem` | `androidx.media3.common.MediaItem` |
|
||||
| `com.google.android.exoplayer2.Player` | `androidx.media3.common.Player` |
|
||||
| `com.google.android.exoplayer2.PlaybackException` | `androidx.media3.common.PlaybackException` |
|
||||
| `com.google.android.exoplayer2.DefaultRenderersFactory` | `androidx.media3.exoplayer.DefaultRenderersFactory` |
|
||||
| `com.google.android.exoplayer2.trackselection.DefaultTrackSelector` | `androidx.media3.exoplayer.trackselection.DefaultTrackSelector` |
|
||||
| `com.google.android.exoplayer2.source.MediaSource` | `androidx.media3.exoplayer.source.MediaSource` |
|
||||
| `com.google.android.exoplayer2.source.hls.HlsMediaSource` | `androidx.media3.exoplayer.hls.HlsMediaSource` |
|
||||
| `com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource` | `androidx.media3.datasource.okhttp.OkHttpDataSource` |
|
||||
| `com.google.android.exoplayer2.ui.PlayerView` | `androidx.media3.ui.PlayerView` |
|
||||
| `com.google.android.exoplayer2.util.Util` | `androidx.media3.common.util.Util` |
|
||||
|
||||
---
|
||||
|
||||
# Notas Importantes
|
||||
|
||||
1. **@OptIn es obligatorio**: Media3 marca algunas APIs como `@UnstableApi`. Agregar `@OptIn(markerClass = UnstableApi.class)` a la clase o metodos que usen estas APIs.
|
||||
|
||||
2. **No hay cambios en la logica**: La API de Media3 es casi identica a ExoPlayer 2.x. Solo cambian los packages.
|
||||
|
||||
3. **Leanback UI**: Agregamos `media3-ui-leanback` para futuras mejoras de Android TV, aunque por ahora usamos el PlayerView standard.
|
||||
|
||||
4. **MediaSession**: Agregamos `media3-session` para integracion con controles del sistema (play/pause desde el launcher de Android TV). Esto se puede implementar despues.
|
||||
|
||||
5. **Compatibilidad**: Media3 1.5.0 requiere minSdk 21 (igual que antes), no hay cambios de compatibilidad.
|
||||
|
||||
---
|
||||
|
||||
# Errores Comunes y Soluciones
|
||||
|
||||
## Error: "Cannot find symbol: class PlayerView"
|
||||
**Causa**: El import o el XML tienen el namespace incorrecto.
|
||||
**Solucion**: Verificar que sea `androidx.media3.ui.PlayerView` en Java y XML.
|
||||
|
||||
## Error: "This declaration is opt-in"
|
||||
**Causa**: Falta la anotacion @OptIn.
|
||||
**Solucion**: Agregar `@OptIn(markerClass = UnstableApi.class)` antes de la clase.
|
||||
|
||||
## Error: "Cannot resolve symbol 'HlsMediaSource'"
|
||||
**Causa**: Falta la dependencia `media3-exoplayer-hls`.
|
||||
**Solucion**: Verificar que `implementation 'androidx.media3:media3-exoplayer-hls:1.5.0'` este en build.gradle.
|
||||
|
||||
## Error: "Cannot resolve symbol 'OkHttpDataSource'"
|
||||
**Causa**: Falta la dependencia `media3-datasource-okhttp`.
|
||||
**Solucion**: Verificar que `implementation 'androidx.media3:media3-datasource-okhttp:1.5.0'` este en build.gradle.
|
||||
|
||||
---
|
||||
|
||||
# Checklist Final
|
||||
|
||||
- [ ] build.gradle: Dependencias actualizadas a Media3 1.5.0
|
||||
- [ ] build.gradle: Version actualizada a 10.1.0
|
||||
- [ ] PlayerActivity.java: Imports actualizados
|
||||
- [ ] PlayerActivity.java: @OptIn agregado
|
||||
- [ ] activity_player.xml: PlayerView namespace actualizado
|
||||
- [ ] Compilacion exitosa sin errores
|
||||
- [ ] Testing en dispositivo Android TV
|
||||
- [ ] Commit y push realizados
|
||||
- [ ] Release creado en Gitea
|
||||
- [ ] APK subido al release
|
||||
Reference in New Issue
Block a user