Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e14e454c5e | ||
|
|
9360294d22 | ||
|
|
1526766630 | ||
|
|
4e92ee6149 | ||
|
|
cff9658060 | ||
|
|
43439e0a88 | ||
|
|
98473e3b30 | ||
|
|
a4e8deb45a |
639
VLC_MIGRATION_PLAN.md
Normal file
639
VLC_MIGRATION_PLAN.md
Normal file
@@ -0,0 +1,639 @@
|
||||
# VLC Player Migration Plan for Android App
|
||||
|
||||
## Current State Analysis
|
||||
- **Location**: `/home/ren/futbol/`
|
||||
- **Current Player**: ExoPlayer/Media3 1.5.0
|
||||
- **Main Files**:
|
||||
- `app/src/main/java/com/streamplayer/PlayerActivity.java`
|
||||
- `app/src/main/java/com/streamplayer/StreamUrlResolver.java`
|
||||
- `app/src/main/res/layout/activity_player.xml`
|
||||
- **Key Features**: HLS streams, custom headers, retry logic, loading indicators, error handling
|
||||
|
||||
## Target State
|
||||
- **New Player**: libvlc for Android (VLC Android SDK)
|
||||
- **DRM Support**: ClearKey DRM for protected streams
|
||||
- **Preserve**: All existing functionality
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Build Configuration Changes
|
||||
|
||||
### File: `app/build.gradle`
|
||||
|
||||
**Remove Media3 dependencies:**
|
||||
```gradle
|
||||
// REMOVE these lines (52-57):
|
||||
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'
|
||||
```
|
||||
|
||||
**Add VLC Android SDK dependency:**
|
||||
```gradle
|
||||
// ADD after line 57:
|
||||
// VLC Android SDK
|
||||
implementation 'org.videolan.android:libvlc-all:3.5.4'
|
||||
// Alternative: Use specific modules for smaller APK
|
||||
// implementation 'org.videolan.android:libvlc:3.5.4'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Layout Changes
|
||||
|
||||
### File: `app/src/main/res/layout/activity_player.xml`
|
||||
|
||||
**Current (lines 10-15):**
|
||||
```xml
|
||||
<androidx.media3.ui.PlayerView
|
||||
android:id="@+id/player_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:resize_mode="fill"
|
||||
app:use_controller="true" />
|
||||
```
|
||||
|
||||
**Replace with VLC SurfaceView:**
|
||||
```xml
|
||||
<org.videolan.libvlc.util.VLCVideoLayout
|
||||
android:id="@+id/player_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<!-- OR use SurfaceView directly for more control -->
|
||||
<SurfaceView
|
||||
android:id="@+id/player_surface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
```
|
||||
|
||||
**Note**: Keep all other UI elements unchanged (toolbar, loading indicator, error message).
|
||||
|
||||
---
|
||||
|
||||
## Phase 3: PlayerActivity Rewrite
|
||||
|
||||
### File: `app/src/main/java/com/streamplayer/PlayerActivity.java`
|
||||
|
||||
**Import Changes:**
|
||||
```java
|
||||
// REMOVE these imports (14-28):
|
||||
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.exoplayer.drm.DrmSessionManager;
|
||||
import androidx.media3.ui.PlayerView;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
|
||||
// ADD VLC imports:
|
||||
import org.videolan.libvlc.LibVLC;
|
||||
import org.videolan.libvlc.Media;
|
||||
import org.videolan.libvlc.MediaPlayer;
|
||||
import org.videolan.libvlc.interfaces.IVLCVout;
|
||||
import org.videolan.libvlc.util.VLCVideoLayout;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.SurfaceHolder;
|
||||
```
|
||||
|
||||
**Class Member Variables (lines 51-66):**
|
||||
```java
|
||||
// REPLACE:
|
||||
private PlayerView playerView;
|
||||
private ExoPlayer player;
|
||||
private DefaultTrackSelector trackSelector;
|
||||
|
||||
// WITH:
|
||||
private VLCVideoLayout playerView; // OR SurfaceView playerSurface
|
||||
private LibVLC libVlc;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private SurfaceView surfaceView;
|
||||
```
|
||||
|
||||
**onCreate Method (lines 68-98):**
|
||||
```java
|
||||
// MODIFY initViews() call:
|
||||
private void initViews() {
|
||||
playerView = findViewById(R.id.player_view); // VLCVideoLayout
|
||||
// OR if using SurfaceView:
|
||||
surfaceView = findViewById(R.id.player_surface);
|
||||
|
||||
loadingIndicator = findViewById(R.id.loading_indicator);
|
||||
errorMessage = findViewById(R.id.error_message);
|
||||
channelLabel = findViewById(R.id.player_channel_label);
|
||||
closeButton = findViewById(R.id.close_button);
|
||||
playerToolbar = findViewById(R.id.player_toolbar);
|
||||
|
||||
closeButton.setOnClickListener(v -> finish());
|
||||
playerView.setOnClickListener(v -> toggleOverlay());
|
||||
// For SurfaceView:
|
||||
// surfaceView.setOnClickListener(v -> toggleOverlay());
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 4: VLC Player Implementation Details
|
||||
|
||||
### 4.1 Initialize VLC with Custom Headers
|
||||
|
||||
**New Method: `startPlayback(String streamUrl)`**
|
||||
```java
|
||||
private void startPlayback(String streamUrl) {
|
||||
try {
|
||||
releasePlayer();
|
||||
lastStreamUrl = streamUrl;
|
||||
retryCount = 0;
|
||||
|
||||
// Create LibVLC instance with options
|
||||
ArrayList<String> options = new ArrayList<>();
|
||||
|
||||
// Network options
|
||||
options.add("--network-caching=1500");
|
||||
options.add("--clock-jitter=0");
|
||||
options.add("--clock-synchro=0");
|
||||
|
||||
// HTTP options for headers
|
||||
options.add(":http-user-agent=" + USER_AGENT);
|
||||
options.add(":http-referrer=" + "http://streamtp10.com/");
|
||||
|
||||
// SSL options (accept all certificates)
|
||||
options.add("--no-xlib");
|
||||
options.add(":rtsp-tcp");
|
||||
options.add(":no-cert-check");
|
||||
|
||||
// Create LibVLC
|
||||
libVlc = new LibVLC(this, options);
|
||||
|
||||
// Create MediaPlayer
|
||||
mediaPlayer = new MediaPlayer(libVlc);
|
||||
|
||||
// Set up event listeners
|
||||
setupMediaPlayerListeners();
|
||||
|
||||
// Create Media with custom headers
|
||||
Media media = new Media(libVlc, android.net.Uri.parse(streamUrl));
|
||||
|
||||
// Add headers via Media options
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Referer", "http://streamtp10.com/");
|
||||
headers.put("User-Agent", USER_AGENT);
|
||||
media.addOption(":http-user-agent=" + USER_AGENT);
|
||||
media.addOption(":http-referrer=http://streamtp10.com/");
|
||||
|
||||
mediaPlayer.setMedia(media);
|
||||
media.release();
|
||||
|
||||
// Set up video output
|
||||
IVLCVout vout = mediaPlayer.getVLCVout();
|
||||
if (playerView instanceof VLCVideoLayout) {
|
||||
vout.setVideoView(playerView);
|
||||
} else if (surfaceView != null) {
|
||||
vout.setVideoView(surfaceView);
|
||||
}
|
||||
vout.attachViews();
|
||||
|
||||
// Start playback
|
||||
mediaPlayer.play();
|
||||
setOverlayVisible(false);
|
||||
|
||||
} catch (Exception e) {
|
||||
showError("Error al inicializar reproductor: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 Player Event Listeners
|
||||
|
||||
**New Method: `setupMediaPlayerListeners()`**
|
||||
```java
|
||||
private void setupMediaPlayerListeners() {
|
||||
// MediaPlayer.EventListener using the VLC event system
|
||||
mediaPlayer.setEventListener(new MediaPlayer.EventListener() {
|
||||
@Override
|
||||
public void onEvent(MediaPlayer.Event event) {
|
||||
switch (event.type) {
|
||||
case MediaPlayer.Event.Playing:
|
||||
// Equivalent to STATE_READY
|
||||
runOnUiThread(() -> {
|
||||
showLoading(false);
|
||||
retryCount = 0;
|
||||
});
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.Buffering:
|
||||
// Buffering state (0.0 to 1.0)
|
||||
float bufferPercent = event.getBuffering();
|
||||
runOnUiThread(() -> showLoading(bufferPercent < 1.0f));
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.EncounteredError:
|
||||
// Error occurred
|
||||
runOnUiThread(() -> handlePlaybackError("Error de reproducción VLC"));
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.EndReached:
|
||||
// Stream ended
|
||||
runOnUiThread(() -> finish());
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.Stopped:
|
||||
// Playback stopped
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.Paused:
|
||||
// Playback paused
|
||||
break;
|
||||
|
||||
case MediaPlayer.Event.Opening:
|
||||
// Stream opening
|
||||
runOnUiThread(() -> showLoading(true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 Error Handling with Retry
|
||||
|
||||
**New Method: `handlePlaybackError(String errorMessage)`**
|
||||
```java
|
||||
private void handlePlaybackError(String errorMsg) {
|
||||
boolean isRetryableError =
|
||||
errorMsg.contains("404") ||
|
||||
errorMsg.contains("403") ||
|
||||
errorMsg.contains("timeout") ||
|
||||
errorMsg.contains("Network") ||
|
||||
errorMsg.contains("Connection");
|
||||
|
||||
if (isRetryableError && retryCount < MAX_RETRIES) {
|
||||
retryCount++;
|
||||
runOnUiThread(() -> {
|
||||
showLoading(true);
|
||||
showError("Error de conexión. Reintentando... (" + retryCount + "/" + MAX_RETRIES + ")");
|
||||
});
|
||||
|
||||
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
|
||||
if (lastStreamUrl != null) {
|
||||
startPlayback(lastStreamUrl);
|
||||
} else {
|
||||
loadChannel();
|
||||
}
|
||||
}, 2000);
|
||||
} else {
|
||||
String finalMessage = "Error al reproducir: " + errorMsg;
|
||||
if (retryCount >= MAX_RETRIES) {
|
||||
finalMessage += "\n\nSe agotaron los reintentos (" + MAX_RETRIES + ").";
|
||||
}
|
||||
showError(finalMessage);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 Player Lifecycle Methods
|
||||
|
||||
**Replace releasePlayer() (lines 257-262):**
|
||||
```java
|
||||
private void releasePlayer() {
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.getVLCVout().detachViews();
|
||||
mediaPlayer.release();
|
||||
mediaPlayer = null;
|
||||
}
|
||||
if (libVlc != null) {
|
||||
libVlc.release();
|
||||
libVlc = null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Update lifecycle methods:**
|
||||
```java
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (mediaPlayer != null && !mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.play();
|
||||
} else if (channelUrl != null && libVlc == null) {
|
||||
loadChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
|
||||
mediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
// Keep player for quick resume, don't release
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
releasePlayer();
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 5: DRM Support (ClearKey)
|
||||
|
||||
### ClearKey DRM Implementation Example
|
||||
|
||||
**New Class: `VlcDrmManager.java`**
|
||||
**Location**: `app/src/main/java/com/streamplayer/VlcDrmManager.java`
|
||||
|
||||
```java
|
||||
package com.streamplayer;
|
||||
|
||||
import org.videolan.libvlc.Media;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handles DRM configuration for VLC Media Player
|
||||
* Supports ClearKey DRM for protected streaming services
|
||||
*/
|
||||
public class VlcDrmManager {
|
||||
|
||||
// ClearKey DRM configuration
|
||||
private static final String CLEARKEY_KEY_SYSTEM = "org.w3.clearkey";
|
||||
|
||||
/**
|
||||
* Configure ClearKey DRM for a Media object
|
||||
* @param media The VLC Media object
|
||||
* @param keyId The key ID (extracted from manifest or license server)
|
||||
* @param key The content key
|
||||
*/
|
||||
public static void configureClearKey(Media media, String keyId, String key) {
|
||||
if (media == null || keyId == null || key == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// VLC uses a specific format for ClearKey
|
||||
// Format: keyid:key
|
||||
String keyPair = keyId + ":" + key;
|
||||
media.addOption(":demux=avformat");
|
||||
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
|
||||
media.addOption(":key=" + keyPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ClearKey DRM with multiple keys
|
||||
* @param media The VLC Media object
|
||||
* @param keys Map of keyId -> key pairs
|
||||
*/
|
||||
public static void configureClearKey(Media media, Map<String, String> keys) {
|
||||
if (media == null || keys == null || keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
media.addOption(":demux=avformat");
|
||||
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
|
||||
|
||||
for (Map.Entry<String, String> entry : keys.entrySet()) {
|
||||
String keyPair = entry.getKey() + ":" + entry.getValue();
|
||||
media.addOption(":key=" + keyPair);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Widevine DRM (for reference, if needed later)
|
||||
* VLC supports Widevine via specific options
|
||||
*/
|
||||
public static void configureWidevine(Media media, String drmServerUrl) {
|
||||
if (media == null || drmServerUrl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
media.addOption(":drm=widevine");
|
||||
media.addOption(":aes-key=" + drmServerUrl);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Extracting ClearKey Keys from Stream
|
||||
|
||||
**Update `StreamUrlResolver.java` to extract DRM info:**
|
||||
|
||||
Add this method to `StreamUrlResolver`:
|
||||
```java
|
||||
/**
|
||||
* Extract ClearKey DRM keys from JSON in HTML
|
||||
* @return Map of keyId -> key pairs, or null if no DRM found
|
||||
*/
|
||||
public static Map<String, String> extractClearKeyKeys(String html) {
|
||||
Map<String, String> keys = new HashMap<>();
|
||||
|
||||
try {
|
||||
// Pattern to find ClearKey key IDs and keys
|
||||
// Common patterns in protected streaming services
|
||||
Pattern clearkeyPattern = Pattern.compile(
|
||||
"\"kid\"\\s*:\\s*\"([^\"]+)\".*?\"k\"\\s*:\\s*\"([^\"]+)\"",
|
||||
Pattern.DOTALL
|
||||
);
|
||||
|
||||
Matcher matcher = clearkeyPattern.matcher(html);
|
||||
while (matcher.find()) {
|
||||
String keyId = matcher.group(1);
|
||||
String key = matcher.group(2);
|
||||
keys.put(keyId, key);
|
||||
}
|
||||
|
||||
// Alternative pattern for JWPlayer with DRM
|
||||
Pattern jwDrmPattern = Pattern.compile(
|
||||
"\"drm\"\\s*:\\s*\\{[^}]*\"clearkey\"\\s*:\\s*\\{[^}]*\"keyId\"\\s*:\\s*\"([^\"]+)\"[^}]*\"key\"\\s*:\\s*\"([^\"]+)\"",
|
||||
Pattern.DOTALL
|
||||
);
|
||||
|
||||
Matcher jwMatcher = jwDrmPattern.matcher(html);
|
||||
while (jwMatcher.find()) {
|
||||
String keyId = jwMatcher.group(1);
|
||||
String key = jwMatcher.group(2);
|
||||
keys.put(keyId, key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Return empty map on error
|
||||
}
|
||||
|
||||
return keys.isEmpty() ? null : keys;
|
||||
}
|
||||
```
|
||||
|
||||
### Using DRM in PlayerActivity
|
||||
|
||||
**Modify `startPlayback()` to handle DRM:**
|
||||
```java
|
||||
// After loading stream URL, also check for DRM keys
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String resolvedUrl = StreamUrlResolver.resolve(channelUrl);
|
||||
Map<String, String> drmKeys = StreamUrlResolver.extractClearKeyKeys(html); // Need to modify resolver to also return HTML
|
||||
|
||||
runOnUiThread(() -> startPlayback(resolvedUrl, drmKeys));
|
||||
} catch (IOException e) {
|
||||
runOnUiThread(() -> showError("No se pudo conectar con el canal: " + e.getMessage()));
|
||||
}
|
||||
}).start();
|
||||
|
||||
private void startPlayback(String streamUrl, Map<String, String> drmKeys) {
|
||||
// ... existing VLC setup code ...
|
||||
|
||||
Media media = new Media(libVlc, android.net.Uri.parse(streamUrl));
|
||||
|
||||
// Add headers
|
||||
media.addOption(":http-user-agent=" + USER_AGENT);
|
||||
media.addOption(":http-referrer=http://streamtp10.com/");
|
||||
|
||||
// Add DRM if available
|
||||
if (drmKeys != null && !drmKeys.isEmpty()) {
|
||||
VlcDrmManager.configureClearKey(media, drmKeys);
|
||||
}
|
||||
|
||||
// ... rest of the setup ...
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 6: Additional Files
|
||||
|
||||
### New File: `VlcPlayerConfig.java`
|
||||
**Location**: `app/src/main/java/com/streamplayer/VlcPlayerConfig.java`
|
||||
|
||||
```java
|
||||
package com.streamplayer;
|
||||
|
||||
/**
|
||||
* Configuration constants for VLC Player
|
||||
*/
|
||||
public class VlcPlayerConfig {
|
||||
|
||||
// Network caching (ms)
|
||||
public static final int NETWORK_CACHING = 1500;
|
||||
|
||||
// Live streaming caching (ms)
|
||||
public static final int LIVE_CACHING = 5000;
|
||||
|
||||
// User Agent
|
||||
public static final String USER_AGENT =
|
||||
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36";
|
||||
|
||||
// Hardware acceleration options
|
||||
public static final String HW_ACCELERATION = "automatic"; // or "full", "none", "decoding", "rendering"
|
||||
|
||||
// Chroma format
|
||||
public static final String CHROMA = "RV32"; // or YV12, NV12
|
||||
|
||||
// Audio output
|
||||
public static final String AUDIO_OUTPUT = "opensles";
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 7: Summary of File Changes
|
||||
|
||||
| File Path | Change Type | Description |
|
||||
|-----------|-------------|-------------|
|
||||
| `app/build.gradle` | Modify | Remove Media3 deps, add VLC SDK |
|
||||
| `app/src/main/res/layout/activity_player.xml` | Modify | Replace PlayerView with VLCVideoLayout |
|
||||
| `app/src/main/java/com/streamplayer/PlayerActivity.java` | Rewrite | Complete VLC integration |
|
||||
| `app/src/main/java/com/streamplayer/VlcDrmManager.java` | New | DRM configuration handler |
|
||||
| `app/src/main/java/com/streamplayer/VlcPlayerConfig.java` | New | VLC configuration constants |
|
||||
| `app/src/main/java/com/streamplayer/StreamUrlResolver.java` | Modify | Add DRM key extraction |
|
||||
|
||||
---
|
||||
|
||||
## Phase 8: VLC-Specific Notes
|
||||
|
||||
### HTTP Headers in VLC
|
||||
VLC handles HTTP headers differently than ExoPlayer:
|
||||
- Headers are set via Media.addOption() with colon prefix
|
||||
- Format: `:http-header-name=value`
|
||||
- Common options:
|
||||
- `:http-user-agent=<value>`
|
||||
- `:http-referrer=<value>`
|
||||
- `:http-cookie=<value>`
|
||||
|
||||
### VLC Events vs ExoPlayer States
|
||||
|
||||
| ExoPlayer State | VLC Event |
|
||||
|----------------|-----------|
|
||||
| STATE_IDLE | N/A (not initialized) |
|
||||
| STATE_BUFFERING | Event.Buffering |
|
||||
| STATE_READY | Event.Playing |
|
||||
| STATE_ENDED | Event.EndReached |
|
||||
|
||||
### DRM Support Comparison
|
||||
| Feature | ExoPlayer | VLC |
|
||||
|---------|-----------|-----|
|
||||
| Widevine | Native | Limited |
|
||||
| ClearKey | Via DRM module | Via libavformat |
|
||||
| PlayReady | Native | Limited |
|
||||
| FairPlay | No | Limited |
|
||||
|
||||
---
|
||||
|
||||
## Phase 9: Testing Checklist
|
||||
|
||||
1. [ ] Basic HLS stream playback
|
||||
2. [ ] HTTP headers (Referer, User-Agent) applied correctly
|
||||
3. [ ] Loading indicator shows/hides correctly
|
||||
4. [ ] Error messages display properly
|
||||
5. [ ] Retry logic works on connection failure
|
||||
6. [ ] Screen stays on during playback
|
||||
7. [ ] Overlay toggle works on tap
|
||||
8. [ ] Close button returns to main activity
|
||||
9. [ ] App handles pause/resume correctly
|
||||
10. [ ] Memory leaks checked (no retained VLC instances)
|
||||
11. [ ] DRM streams play correctly
|
||||
12. [ ] SSL certificate bypass works
|
||||
|
||||
---
|
||||
|
||||
## Phase 10: Fallback Strategy
|
||||
|
||||
If VLC doesn't work as expected, consider:
|
||||
1. **Hybrid approach**: Keep ExoPlayer as fallback, use VLC for DRM-only streams
|
||||
2. **Alternative libraries**:
|
||||
- Vitamio (deprecated but still works)
|
||||
- NKD-Player (wrapper around FFmpeg)
|
||||
- Build custom FFmpeg integration
|
||||
3. **Webview approach**: Use embedded browser for DRM content
|
||||
|
||||
---
|
||||
|
||||
## Appendix: VLC SDK Documentation Links
|
||||
|
||||
- VLC Android SDK: https://code.videolan.org/videolan/vlc-android
|
||||
- VLC LibVLC API: https://code.videolan.org/videolan/vlc-android/-/tree/master/libvlc
|
||||
- VLC Wiki on Android: https://wiki.videolan.org/AndroidCompile
|
||||
- ClearKey DRM spec: https://w3c.github.io/encrypted-media/format-registry/initdata/cenc.html
|
||||
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.streamplayer"
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
versionCode 100108
|
||||
versionName "10.1.8"
|
||||
versionCode 100200
|
||||
versionName "11.0.0"
|
||||
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
|
||||
}
|
||||
|
||||
@@ -47,16 +47,14 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.3.2'
|
||||
implementation 'androidx.media3:media3-exoplayer:1.4.1'
|
||||
implementation 'androidx.media3:media3-exoplayer-hls:1.4.1'
|
||||
implementation 'androidx.media3:media3-ui:1.4.1'
|
||||
|
||||
// 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'
|
||||
// VLC Player para reproduccion de video (soporte DRM mejorado)
|
||||
implementation 'org.videolan.android:libvlc-all:3.4.4'
|
||||
|
||||
// OkHttp con DNS over HTTPS
|
||||
// OkHttp con DNS over HTTPS (para StreamUrlResolver)
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.0'
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-feature
|
||||
android:name="android.software.leanback"
|
||||
|
||||
@@ -12,72 +12,72 @@ public final class ChannelRepository {
|
||||
|
||||
private static List<StreamChannel> createChannels() {
|
||||
List<StreamChannel> channels = new ArrayList<>(Arrays.asList(
|
||||
new StreamChannel("ESPN", "https://streamtp10.com/global2.php?stream=espn"),
|
||||
new StreamChannel("ESPN 2", "https://streamtp10.com/global2.php?stream=espn2"),
|
||||
new StreamChannel("ESPN 3", "https://streamtp10.com/global2.php?stream=espn3"),
|
||||
new StreamChannel("ESPN 4", "https://streamtp10.com/global2.php?stream=espn4"),
|
||||
new StreamChannel("ESPN 3 MX", "https://streamtp10.com/global2.php?stream=espn3mx"),
|
||||
new StreamChannel("ESPN 5", "https://streamtp10.com/global2.php?stream=espn5"),
|
||||
new StreamChannel("Fox Sports 3 MX", "https://streamtp10.com/global2.php?stream=foxsports3mx"),
|
||||
new StreamChannel("ESPN 6", "https://streamtp10.com/global2.php?stream=espn6"),
|
||||
new StreamChannel("Fox Sports MX", "https://streamtp10.com/global2.php?stream=foxsportsmx"),
|
||||
new StreamChannel("ESPN 7", "https://streamtp10.com/global2.php?stream=espn7"),
|
||||
new StreamChannel("Azteca Deportes", "https://streamtp10.com/global2.php?stream=azteca_deportes"),
|
||||
new StreamChannel("Win Plus", "https://streamtp10.com/global2.php?stream=winplus"),
|
||||
new StreamChannel("DAZN 1", "https://streamtp10.com/global2.php?stream=dazn1"),
|
||||
new StreamChannel("Win Plus 2", "https://streamtp10.com/global2.php?stream=winplus2"),
|
||||
new StreamChannel("DAZN 2", "https://streamtp10.com/global2.php?stream=dazn2"),
|
||||
new StreamChannel("Win Sports", "https://streamtp10.com/global2.php?stream=winsports"),
|
||||
new StreamChannel("DAZN LaLiga", "https://streamtp10.com/global2.php?stream=dazn_laliga"),
|
||||
new StreamChannel("Win Plus Online 1", "https://streamtp10.com/global2.php?stream=winplusonline1"),
|
||||
new StreamChannel("Caracol TV", "https://streamtp10.com/global2.php?stream=caracoltv"),
|
||||
new StreamChannel("Fox 1 AR", "https://streamtp10.com/global2.php?stream=fox1ar"),
|
||||
new StreamChannel("Fox 2 USA", "https://streamtp10.com/global2.php?stream=fox_2_usa"),
|
||||
new StreamChannel("Fox 2 AR", "https://streamtp10.com/global2.php?stream=fox2ar"),
|
||||
new StreamChannel("TNT 1 GB", "https://streamtp10.com/global2.php?stream=tnt_1_gb"),
|
||||
new StreamChannel("TNT 2 GB", "https://streamtp10.com/global2.php?stream=tnt_2_gb"),
|
||||
new StreamChannel("Fox 3 AR", "https://streamtp10.com/global2.php?stream=fox3ar"),
|
||||
new StreamChannel("Universo USA", "https://streamtp10.com/global2.php?stream=universo_usa"),
|
||||
new StreamChannel("DSports", "https://streamtp10.com/global2.php?stream=dsports"),
|
||||
new StreamChannel("Univision USA", "https://streamtp10.com/global2.php?stream=univision_usa"),
|
||||
new StreamChannel("DSports 2", "https://streamtp10.com/global2.php?stream=dsports2"),
|
||||
new StreamChannel("Fox Deportes USA", "https://streamtp10.com/global2.php?stream=fox_deportes_usa"),
|
||||
new StreamChannel("DSports Plus", "https://streamtp10.com/global2.php?stream=dsportsplus"),
|
||||
new StreamChannel("Fox Sports 2 MX", "https://streamtp10.com/global2.php?stream=foxsports2mx"),
|
||||
new StreamChannel("TNT Sports Chile", "https://streamtp10.com/global2.php?stream=tntsportschile"),
|
||||
new StreamChannel("Fox Sports Premium", "https://streamtp10.com/global2.php?stream=foxsportspremium"),
|
||||
new StreamChannel("TNT Sports", "https://streamtp10.com/global2.php?stream=tntsports"),
|
||||
new StreamChannel("ESPN MX", "https://streamtp10.com/global2.php?stream=espnmx"),
|
||||
new StreamChannel("ESPN Premium", "https://streamtp10.com/global2.php?stream=espnpremium"),
|
||||
new StreamChannel("ESPN 2 MX", "https://streamtp10.com/global2.php?stream=espn2mx"),
|
||||
new StreamChannel("TyC Sports", "https://streamtp10.com/global2.php?stream=tycsports"),
|
||||
new StreamChannel("TUDN USA", "https://streamtp10.com/global2.php?stream=tudn_usa"),
|
||||
new StreamChannel("Telefe", "https://streamtp10.com/global2.php?stream=telefe"),
|
||||
new StreamChannel("TNT 3 GB", "https://streamtp10.com/global2.php?stream=tnt_3_gb"),
|
||||
new StreamChannel("TV Pública", "https://streamtp10.com/global2.php?stream=tv_publica"),
|
||||
new StreamChannel("Fox 1 USA", "https://streamtp10.com/global2.php?stream=fox_1_usa"),
|
||||
new StreamChannel("Liga 1 Max", "https://streamtp10.com/global2.php?stream=liga1max"),
|
||||
new StreamChannel("Gol TV", "https://streamtp10.com/global2.php?stream=goltv"),
|
||||
new StreamChannel("VTV Plus", "https://streamtp10.com/global2.php?stream=vtvplus"),
|
||||
new StreamChannel("ESPN Deportes", "https://streamtp10.com/global2.php?stream=espndeportes"),
|
||||
new StreamChannel("Gol Perú", "https://streamtp10.com/global2.php?stream=golperu"),
|
||||
new StreamChannel("TNT 4 GB", "https://streamtp10.com/global2.php?stream=tnt_4_gb"),
|
||||
new StreamChannel("SportTV BR 1", "https://streamtp10.com/global2.php?stream=sporttvbr1"),
|
||||
new StreamChannel("SportTV BR 2", "https://streamtp10.com/global2.php?stream=sporttvbr2"),
|
||||
new StreamChannel("SportTV BR 3", "https://streamtp10.com/global2.php?stream=sporttvbr3"),
|
||||
new StreamChannel("Premiere 1", "https://streamtp10.com/global2.php?stream=premiere1"),
|
||||
new StreamChannel("Premiere 2", "https://streamtp10.com/global2.php?stream=premiere2"),
|
||||
new StreamChannel("Premiere 3", "https://streamtp10.com/global2.php?stream=premiere3"),
|
||||
new StreamChannel("ESPN NL 1", "https://streamtp10.com/global2.php?stream=espn_nl1"),
|
||||
new StreamChannel("ESPN NL 2", "https://streamtp10.com/global2.php?stream=espn_nl2"),
|
||||
new StreamChannel("ESPN NL 3", "https://streamtp10.com/global2.php?stream=espn_nl3"),
|
||||
new StreamChannel("Caliente TV MX", "https://streamtp10.com/global2.php?stream=calientetvmx"),
|
||||
new StreamChannel("USA Network", "https://streamtp10.com/global2.php?stream=usa_network"),
|
||||
new StreamChannel("TyC Internacional", "https://streamtp10.com/global2.php?stream=tycinternacional"),
|
||||
new StreamChannel("Canal 5 MX", "https://streamtp10.com/global2.php?stream=canal5mx"),
|
||||
new StreamChannel("TUDN MX", "https://streamtp10.com/global2.php?stream=TUDNMX"),
|
||||
new StreamChannel("FUTV", "https://streamtp10.com/global2.php?stream=futv"),
|
||||
new StreamChannel("LaLiga Hypermotion", "https://streamtp10.com/global2.php?stream=laligahypermotion")
|
||||
new StreamChannel("ESPN", "http://streamtp10.com/global2.php?stream=espn"),
|
||||
new StreamChannel("ESPN 2", "http://streamtp10.com/global2.php?stream=espn2"),
|
||||
new StreamChannel("ESPN 3", "http://streamtp10.com/global2.php?stream=espn3"),
|
||||
new StreamChannel("ESPN 4", "http://streamtp10.com/global2.php?stream=espn4"),
|
||||
new StreamChannel("ESPN 3 MX", "http://streamtp10.com/global2.php?stream=espn3mx"),
|
||||
new StreamChannel("ESPN 5", "http://streamtp10.com/global2.php?stream=espn5"),
|
||||
new StreamChannel("Fox Sports 3 MX", "http://streamtp10.com/global2.php?stream=foxsports3mx"),
|
||||
new StreamChannel("ESPN 6", "http://streamtp10.com/global2.php?stream=espn6"),
|
||||
new StreamChannel("Fox Sports MX", "http://streamtp10.com/global2.php?stream=foxsportsmx"),
|
||||
new StreamChannel("ESPN 7", "http://streamtp10.com/global2.php?stream=espn7"),
|
||||
new StreamChannel("Azteca Deportes", "http://streamtp10.com/global2.php?stream=azteca_deportes"),
|
||||
new StreamChannel("Win Plus", "http://streamtp10.com/global2.php?stream=winplus"),
|
||||
new StreamChannel("DAZN 1", "http://streamtp10.com/global2.php?stream=dazn1"),
|
||||
new StreamChannel("Win Plus 2", "http://streamtp10.com/global2.php?stream=winplus2"),
|
||||
new StreamChannel("DAZN 2", "http://streamtp10.com/global2.php?stream=dazn2"),
|
||||
new StreamChannel("Win Sports", "http://streamtp10.com/global2.php?stream=winsports"),
|
||||
new StreamChannel("DAZN LaLiga", "http://streamtp10.com/global2.php?stream=dazn_laliga"),
|
||||
new StreamChannel("Win Plus Online 1", "http://streamtp10.com/global2.php?stream=winplusonline1"),
|
||||
new StreamChannel("Caracol TV", "http://streamtp10.com/global2.php?stream=caracoltv"),
|
||||
new StreamChannel("Fox 1 AR", "http://streamtp10.com/global2.php?stream=fox1ar"),
|
||||
new StreamChannel("Fox 2 USA", "http://streamtp10.com/global2.php?stream=fox_2_usa"),
|
||||
new StreamChannel("Fox 2 AR", "http://streamtp10.com/global2.php?stream=fox2ar"),
|
||||
new StreamChannel("TNT 1 GB", "http://streamtp10.com/global2.php?stream=tnt_1_gb"),
|
||||
new StreamChannel("TNT 2 GB", "http://streamtp10.com/global2.php?stream=tnt_2_gb"),
|
||||
new StreamChannel("Fox 3 AR", "http://streamtp10.com/global2.php?stream=fox3ar"),
|
||||
new StreamChannel("Universo USA", "http://streamtp10.com/global2.php?stream=universo_usa"),
|
||||
new StreamChannel("DSports", "http://streamtp10.com/global2.php?stream=dsports"),
|
||||
new StreamChannel("Univision USA", "http://streamtp10.com/global2.php?stream=univision_usa"),
|
||||
new StreamChannel("DSports 2", "http://streamtp10.com/global2.php?stream=dsports2"),
|
||||
new StreamChannel("Fox Deportes USA", "http://streamtp10.com/global2.php?stream=fox_deportes_usa"),
|
||||
new StreamChannel("DSports Plus", "http://streamtp10.com/global2.php?stream=dsportsplus"),
|
||||
new StreamChannel("Fox Sports 2 MX", "http://streamtp10.com/global2.php?stream=foxsports2mx"),
|
||||
new StreamChannel("TNT Sports Chile", "http://streamtp10.com/global2.php?stream=tntsportschile"),
|
||||
new StreamChannel("Fox Sports Premium", "http://streamtp10.com/global2.php?stream=foxsportspremium"),
|
||||
new StreamChannel("TNT Sports", "http://streamtp10.com/global2.php?stream=tntsports"),
|
||||
new StreamChannel("ESPN MX", "http://streamtp10.com/global2.php?stream=espnmx"),
|
||||
new StreamChannel("ESPN Premium", "http://streamtp10.com/global2.php?stream=espnpremium"),
|
||||
new StreamChannel("ESPN 2 MX", "http://streamtp10.com/global2.php?stream=espn2mx"),
|
||||
new StreamChannel("TyC Sports", "http://streamtp10.com/global2.php?stream=tycsports"),
|
||||
new StreamChannel("TUDN USA", "http://streamtp10.com/global2.php?stream=tudn_usa"),
|
||||
new StreamChannel("Telefe", "http://streamtp10.com/global2.php?stream=telefe"),
|
||||
new StreamChannel("TNT 3 GB", "http://streamtp10.com/global2.php?stream=tnt_3_gb"),
|
||||
new StreamChannel("TV Pública", "http://streamtp10.com/global2.php?stream=tv_publica"),
|
||||
new StreamChannel("Fox 1 USA", "http://streamtp10.com/global2.php?stream=fox_1_usa"),
|
||||
new StreamChannel("Liga 1 Max", "http://streamtp10.com/global2.php?stream=liga1max"),
|
||||
new StreamChannel("Gol TV", "http://streamtp10.com/global2.php?stream=goltv"),
|
||||
new StreamChannel("VTV Plus", "http://streamtp10.com/global2.php?stream=vtvplus"),
|
||||
new StreamChannel("ESPN Deportes", "http://streamtp10.com/global2.php?stream=espndeportes"),
|
||||
new StreamChannel("Gol Perú", "http://streamtp10.com/global2.php?stream=golperu"),
|
||||
new StreamChannel("TNT 4 GB", "http://streamtp10.com/global2.php?stream=tnt_4_gb"),
|
||||
new StreamChannel("SportTV BR 1", "http://streamtp10.com/global2.php?stream=sporttvbr1"),
|
||||
new StreamChannel("SportTV BR 2", "http://streamtp10.com/global2.php?stream=sporttvbr2"),
|
||||
new StreamChannel("SportTV BR 3", "http://streamtp10.com/global2.php?stream=sporttvbr3"),
|
||||
new StreamChannel("Premiere 1", "http://streamtp10.com/global2.php?stream=premiere1"),
|
||||
new StreamChannel("Premiere 2", "http://streamtp10.com/global2.php?stream=premiere2"),
|
||||
new StreamChannel("Premiere 3", "http://streamtp10.com/global2.php?stream=premiere3"),
|
||||
new StreamChannel("ESPN NL 1", "http://streamtp10.com/global2.php?stream=espn_nl1"),
|
||||
new StreamChannel("ESPN NL 2", "http://streamtp10.com/global2.php?stream=espn_nl2"),
|
||||
new StreamChannel("ESPN NL 3", "http://streamtp10.com/global2.php?stream=espn_nl3"),
|
||||
new StreamChannel("Caliente TV MX", "http://streamtp10.com/global2.php?stream=calientetvmx"),
|
||||
new StreamChannel("USA Network", "http://streamtp10.com/global2.php?stream=usa_network"),
|
||||
new StreamChannel("TyC Internacional", "http://streamtp10.com/global2.php?stream=tycinternacional"),
|
||||
new StreamChannel("Canal 5 MX", "http://streamtp10.com/global2.php?stream=canal5mx"),
|
||||
new StreamChannel("TUDN MX", "http://streamtp10.com/global2.php?stream=TUDNMX"),
|
||||
new StreamChannel("FUTV", "http://streamtp10.com/global2.php?stream=futv"),
|
||||
new StreamChannel("LaLiga Hypermotion", "http://streamtp10.com/global2.php?stream=laligahypermotion")
|
||||
));
|
||||
channels.sort(Comparator.comparing(StreamChannel::getName, String.CASE_INSENSITIVE_ORDER));
|
||||
return Collections.unmodifiableList(channels);
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.streamplayer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.os.Build;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class DNSSetter {
|
||||
|
||||
private static final String[] GOOGLE_DNS = {"8.8.8.8", "8.8.4.4"};
|
||||
|
||||
public static void configureDNSToGoogle(Context context) {
|
||||
try {
|
||||
// Configurar propiedades del sistema para usar DNS específicos
|
||||
System.setProperty("networkaddress.cache.ttl", "60");
|
||||
System.setProperty("networkaddress.cache.negative.ttl", "10");
|
||||
|
||||
// Forzar resolución usando DNS de Google
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
configureModernDNS(context);
|
||||
} else {
|
||||
configureLegacyDNS();
|
||||
}
|
||||
|
||||
// Pre-resolver dominio con DNS de Google
|
||||
preResolveWithGoogleDNS();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error configurando DNS de Google: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureModernDNS(Context context) {
|
||||
try {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
NetworkRequest networkRequest = new NetworkRequest.Builder()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
.build();
|
||||
|
||||
connectivityManager.registerNetworkCallback(networkRequest, new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onAvailable(Network network) {
|
||||
super.onAvailable(network);
|
||||
|
||||
// Configuración para priorizar DNS de Google
|
||||
// Aunque no podemos cambiar DNS directamente sin permisos especiales,
|
||||
// podemos optimizar la configuración de red
|
||||
try {
|
||||
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(network);
|
||||
if (caps != null) {
|
||||
System.out.println("Red configurada con DNS optimizado para streaming");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error en configuración de red: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error configurando DNS moderno: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureLegacyDNS() {
|
||||
try {
|
||||
// Para versiones antiguas, configuramos propiedades del sistema
|
||||
System.setProperty("sun.net.inetaddr.ttl", "60");
|
||||
System.setProperty("sun.net.inetaddr.negative.ttl", "10");
|
||||
|
||||
System.out.println("DNS legacy configurado para streaming");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error configurando DNS legacy: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void preResolveWithGoogleDNS() {
|
||||
try {
|
||||
// Pre-resolver algunos dominios comunes para caching
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
String[] domains = {"streamtp10.com", "google.com", "dns.adguard-dns.com"};
|
||||
for (String domain : domains) {
|
||||
try {
|
||||
InetAddress.getByName(domain);
|
||||
System.out.println("Pre-resuelto: " + domain);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error pre-resolviendo " + domain + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error en pre-resolución: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error en pre-resolución DNS: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGoogleDNSInfo() {
|
||||
return "DNS de Google configurado: " + String.join(", ", GOOGLE_DNS);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -46,11 +45,8 @@ public class DeviceRegistry {
|
||||
|
||||
public DeviceRegistry(Context context) {
|
||||
this.appContext = context.getApplicationContext();
|
||||
this.httpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.callTimeout(20, TimeUnit.SECONDS)
|
||||
.build();
|
||||
// Usar NetworkUtils para obtener cliente con DNS over HTTPS configurado
|
||||
this.httpClient = NetworkUtils.getClient();
|
||||
this.executorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class EventRepository {
|
||||
private static final long CACHE_DURATION = 24L * 60 * 60 * 1000; // 24 horas
|
||||
|
||||
// URL única para eventos (actualizado para evitar bloqueos de ISP)
|
||||
private static final String EVENTS_URL = "https://streamtp10.com/eventos.json";
|
||||
private static final String EVENTS_URL = "http://streamtp10.com/eventos.json";
|
||||
|
||||
public interface Callback {
|
||||
void onSuccess(List<EventItem> events);
|
||||
@@ -151,10 +151,9 @@ public class EventRepository {
|
||||
if (link == null) {
|
||||
return "";
|
||||
}
|
||||
// Actualizado a streamtp10.com
|
||||
String updated = link.replace("streamtpmedia.com", "streamtp10.com")
|
||||
.replace("streamtpcloud.com", "streamtp10.com");
|
||||
return updated.replace("global1.php", "global2.php");
|
||||
// Mantener el endpoint original (global1/global2) que entregue el proveedor.
|
||||
return link.replace("streamtpmedia.com", "streamtp10.com")
|
||||
.replace("streamtpcloud.com", "streamtp10.com");
|
||||
}
|
||||
|
||||
private String extractChannelName(String link) {
|
||||
|
||||
@@ -2,95 +2,115 @@ package com.streamplayer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.Dns;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.dnsoverhttps.DnsOverHttps;
|
||||
|
||||
/**
|
||||
* Utilidad centralizada para configuración de red.
|
||||
* Fuerza DNS over HTTPS con fallback Google -> Cloudflare -> DNS del sistema.
|
||||
*/
|
||||
public class NetworkUtils {
|
||||
|
||||
private static final OkHttpClient CLIENT;
|
||||
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
|
||||
private static final String GOOGLE_DOH_URL = "https://dns.google/dns-query";
|
||||
private static final String CLOUDFLARE_DOH_URL = "https://cloudflare-dns.com/dns-query";
|
||||
|
||||
static {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.writeTimeout(15, TimeUnit.SECONDS)
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(20, TimeUnit.SECONDS)
|
||||
.followRedirects(true)
|
||||
.followSslRedirects(true);
|
||||
.followSslRedirects(true)
|
||||
.retryOnConnectionFailure(true);
|
||||
|
||||
try {
|
||||
// Cliente bootstrap para resolver los dominios de DNS
|
||||
OkHttpClient bootstrap = new OkHttpClient.Builder()
|
||||
.connectTimeout(5, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
// 1. Google DNS over HTTPS (Primario)
|
||||
final DnsOverHttps googleDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get("https://dns.google/dns-query"))
|
||||
.bootstrapDnsHosts(
|
||||
getByIp("8.8.8.8"),
|
||||
getByIp("8.8.4.4"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
// 2. AdGuard DNS over HTTPS (Secundario)
|
||||
final DnsOverHttps adGuardDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get("https://dns.adguard-dns.com/dns-query"))
|
||||
.bootstrapDnsHosts(
|
||||
getByIp("94.140.14.14"),
|
||||
getByIp("94.140.15.15"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
// Configurar DNS con fallback: Google -> AdGuard -> Sistema
|
||||
builder.dns(new Dns() {
|
||||
@Override
|
||||
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||
// Intento 1: Google DNS
|
||||
try {
|
||||
List<InetAddress> result = googleDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) return result;
|
||||
} catch (Exception ignored) {
|
||||
// Falló Google, continuar
|
||||
}
|
||||
|
||||
// Intento 2: AdGuard DNS
|
||||
try {
|
||||
List<InetAddress> result = adGuardDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) return result;
|
||||
} catch (Exception ignored) {
|
||||
// Falló AdGuard, continuar
|
||||
}
|
||||
|
||||
// Intento 3: DNS del Sistema (Fallback final)
|
||||
try {
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
} catch (UnknownHostException e) {
|
||||
throw e;
|
||||
// Configurar para aceptar todos los certificados SSL (útil para diagnosticar problemas de ISP)
|
||||
// NOTA: Esto es temporal para diagnosticar si hay problemas de certificados MITM
|
||||
final TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[]{};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
|
||||
builder.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]);
|
||||
builder.hostnameVerifier((hostname, session) -> true);
|
||||
|
||||
OkHttpClient bootstrap = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(10, TimeUnit.SECONDS)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
|
||||
.hostnameVerifier((hostname, session) -> true)
|
||||
.retryOnConnectionFailure(true)
|
||||
.build();
|
||||
|
||||
final DnsOverHttps googleDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get(GOOGLE_DOH_URL))
|
||||
.bootstrapDnsHosts(
|
||||
InetAddress.getByName("8.8.8.8"),
|
||||
InetAddress.getByName("8.8.4.4"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
final DnsOverHttps cloudflareDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get(CLOUDFLARE_DOH_URL))
|
||||
.bootstrapDnsHosts(
|
||||
InetAddress.getByName("1.1.1.1"),
|
||||
InetAddress.getByName("1.0.0.1"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
builder.dns(hostname -> {
|
||||
try {
|
||||
List<InetAddress> result = googleDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
List<InetAddress> result = cloudflareDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
// Si algo falla en la configuración DNS, usamos por defecto (implícito en el builder)
|
||||
builder.dns(Dns.SYSTEM);
|
||||
System.out.println("Error configurando DNS over HTTPS: " + e.getMessage());
|
||||
}
|
||||
|
||||
CLIENT = builder.build();
|
||||
}
|
||||
|
||||
private static InetAddress getByIp(String ip) throws UnknownHostException {
|
||||
return InetAddress.getByName(ip);
|
||||
}
|
||||
|
||||
public static OkHttpClient getClient() {
|
||||
return CLIENT;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.streamplayer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
@@ -10,37 +14,24 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
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.datasource.DefaultHttpDataSource;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.dnsoverhttps.DnsOverHttps;
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public class PlayerActivity extends AppCompatActivity {
|
||||
|
||||
public static final String EXTRA_CHANNEL_NAME = "extra_channel_name";
|
||||
public static final String EXTRA_CHANNEL_URL = "extra_channel_url";
|
||||
private static final String TAG = "PlayerActivity";
|
||||
private static final long STARTUP_TIMEOUT_MS = 12000L;
|
||||
|
||||
private PlayerView playerView;
|
||||
private ProgressBar loadingIndicator;
|
||||
@@ -50,14 +41,18 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
private View playerToolbar;
|
||||
|
||||
private ExoPlayer player;
|
||||
private DefaultTrackSelector trackSelector;
|
||||
private String channelName;
|
||||
private String channelUrl;
|
||||
private boolean overlayVisible = true;
|
||||
private OkHttpClient okHttpClient;
|
||||
private int retryCount = 0;
|
||||
private static final int MAX_RETRIES = 3;
|
||||
private String lastStreamUrl;
|
||||
private String currentChannelPageUrl;
|
||||
private boolean playbackStarted = false;
|
||||
private boolean alternateSourceAttempted = false;
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
private Runnable startupTimeoutRunnable;
|
||||
private final Object resolveLock = new Object();
|
||||
private int resolveGeneration = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -83,11 +78,11 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
currentChannelPageUrl = channelUrl;
|
||||
|
||||
initViews();
|
||||
channelLabel.setText(channelName);
|
||||
|
||||
DNSSetter.configureDNSToGoogle(this);
|
||||
loadChannel();
|
||||
}
|
||||
|
||||
@@ -101,118 +96,261 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
|
||||
closeButton.setOnClickListener(v -> finish());
|
||||
playerView.setOnClickListener(v -> toggleOverlay());
|
||||
playerView.setUseController(false);
|
||||
}
|
||||
|
||||
private void loadChannel() {
|
||||
showLoading(true);
|
||||
retryCount = 0; // Resetear contador al cargar nuevo canal
|
||||
retryCount = 0;
|
||||
alternateSourceAttempted = false;
|
||||
currentChannelPageUrl = channelUrl;
|
||||
loadChannelFromPageUrl(channelUrl);
|
||||
}
|
||||
|
||||
private void loadChannelFromPageUrl(String pageUrl) {
|
||||
currentChannelPageUrl = pageUrl;
|
||||
final int requestGeneration;
|
||||
synchronized (resolveLock) {
|
||||
resolveGeneration++;
|
||||
requestGeneration = resolveGeneration;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Resolviendo stream desde: " + pageUrl + " (req=" + requestGeneration + ")");
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String resolvedUrl = StreamUrlResolver.resolve(channelUrl);
|
||||
runOnUiThread(() -> startPlayback(resolvedUrl));
|
||||
String resolvedUrl = StreamUrlResolver.resolve(pageUrl);
|
||||
Log.d(TAG, "Stream resuelto: " + resolvedUrl + " (req=" + requestGeneration + ")");
|
||||
runOnUiThread(() -> {
|
||||
if (!isLatestResolveRequest(requestGeneration)) {
|
||||
Log.d(TAG, "Ignorando resultado viejo (req=" + requestGeneration + ")");
|
||||
return;
|
||||
}
|
||||
startPlayback(resolvedUrl);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
runOnUiThread(() -> showError("No se pudo conectar con el canal: " + e.getMessage()));
|
||||
runOnUiThread(() -> {
|
||||
if (!isLatestResolveRequest(requestGeneration)) {
|
||||
return;
|
||||
}
|
||||
if (!tryAlternateSource("No se pudo conectar con el canal. " + e.getMessage())) {
|
||||
showError("No se pudo conectar con el canal: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
runOnUiThread(() -> showError("Error inesperado: " + e.getMessage()));
|
||||
runOnUiThread(() -> {
|
||||
if (!isLatestResolveRequest(requestGeneration)) {
|
||||
return;
|
||||
}
|
||||
if (!tryAlternateSource("Error inesperado al resolver stream. " + e.getMessage())) {
|
||||
showError("Error inesperado: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean isLatestResolveRequest(int requestGeneration) {
|
||||
synchronized (resolveLock) {
|
||||
return requestGeneration == resolveGeneration;
|
||||
}
|
||||
}
|
||||
|
||||
private void startPlayback(String streamUrl) {
|
||||
try {
|
||||
releasePlayer();
|
||||
lastStreamUrl = streamUrl; // Guardar URL para reintentos
|
||||
retryCount = 0; // Resetear contador al iniciar nueva reproducción
|
||||
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this)
|
||||
.setEnableDecoderFallback(true)
|
||||
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
|
||||
lastStreamUrl = streamUrl;
|
||||
retryCount = 0;
|
||||
playbackStarted = false;
|
||||
scheduleStartupTimeout();
|
||||
Log.d(TAG, "Iniciando reproducción: " + streamUrl);
|
||||
|
||||
// Configurar track selector para calidad adaptativa (no forzar máxima calidad)
|
||||
trackSelector = new DefaultTrackSelector(this);
|
||||
DefaultTrackSelector.Parameters params = trackSelector.buildUponParameters()
|
||||
.setForceHighestSupportedBitrate(false) // Permitir calidad adaptativa
|
||||
.setMaxVideoBitrate(Integer.MAX_VALUE) // Sin límite máximo de bitrate
|
||||
.build();
|
||||
trackSelector.setParameters(params);
|
||||
DefaultHttpDataSource.Factory httpFactory = new DefaultHttpDataSource.Factory()
|
||||
.setUserAgent(VlcPlayerConfig.USER_AGENT)
|
||||
.setAllowCrossProtocolRedirects(true)
|
||||
.setConnectTimeoutMs(15000)
|
||||
.setReadTimeoutMs(20000);
|
||||
|
||||
player = new ExoPlayer.Builder(this, renderersFactory)
|
||||
.setTrackSelector(trackSelector)
|
||||
.setSeekForwardIncrementMs(10_000)
|
||||
.setSeekBackIncrementMs(10_000)
|
||||
.build();
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("User-Agent", VlcPlayerConfig.USER_AGENT);
|
||||
httpFactory.setDefaultRequestProperties(headers);
|
||||
|
||||
HlsMediaSource mediaSource = new HlsMediaSource.Factory(httpFactory)
|
||||
.setAllowChunklessPreparation(true)
|
||||
.createMediaSource(MediaItem.fromUri(Uri.parse(streamUrl)));
|
||||
|
||||
player = new ExoPlayer.Builder(this).build();
|
||||
playerView.setPlayer(player);
|
||||
setupPlayerListener();
|
||||
|
||||
player.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onPlaybackStateChanged(int playbackState) {
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
showLoading(false);
|
||||
retryCount = 0; // Resetear contador de reintentos al reproducir exitosamente
|
||||
} else if (playbackState == Player.STATE_BUFFERING) {
|
||||
showLoading(true);
|
||||
}
|
||||
}
|
||||
player.setMediaSource(mediaSource);
|
||||
player.prepare();
|
||||
player.play();
|
||||
setOverlayVisible(false);
|
||||
} catch (Exception e) {
|
||||
cancelStartupTimeout();
|
||||
Log.e(TAG, "Error al iniciar reproducción", e);
|
||||
if (!tryAlternateSource("Error al inicializar reproductor. Probando fuente alterna...")) {
|
||||
showError("Error al inicializar reproductor: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
String errorMsg = error.getMessage() != null ? error.getMessage() : "";
|
||||
String detail = error.getCause() != null ?
|
||||
error.getCause().getMessage() : "";
|
||||
String fullError = errorMsg + " " + detail;
|
||||
private void setupPlayerListener() {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Verificar si es un error que justifica reintento (404, conectividad, etc.)
|
||||
boolean isRetryableError =
|
||||
fullError.contains("404") ||
|
||||
fullError.contains("403") ||
|
||||
fullError.contains("timeout") ||
|
||||
fullError.contains("Unable to connect") ||
|
||||
fullError.contains("Network") ||
|
||||
fullError.contains("source error") ||
|
||||
error.errorCode == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED ||
|
||||
error.errorCode == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT ||
|
||||
error.errorCode == PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS;
|
||||
|
||||
if (isRetryableError && retryCount < MAX_RETRIES) {
|
||||
retryCount++;
|
||||
player.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onPlaybackStateChanged(int playbackState) {
|
||||
switch (playbackState) {
|
||||
case Player.STATE_BUFFERING:
|
||||
Log.d(TAG, "Exo Event: BUFFERING");
|
||||
runOnUiThread(() -> showLoading(true));
|
||||
break;
|
||||
case Player.STATE_READY:
|
||||
Log.d(TAG, "Exo Event: READY");
|
||||
runOnUiThread(() -> {
|
||||
showLoading(true);
|
||||
showError("Error de conexión. Reintentando... (" + retryCount + "/" + MAX_RETRIES + ")");
|
||||
playbackStarted = true;
|
||||
cancelStartupTimeout();
|
||||
showLoading(false);
|
||||
retryCount = 0;
|
||||
});
|
||||
|
||||
// Reintentar después de 2 segundos
|
||||
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
|
||||
if (lastStreamUrl != null) {
|
||||
startPlayback(lastStreamUrl);
|
||||
} else {
|
||||
loadChannel();
|
||||
}
|
||||
}, 2000);
|
||||
} else {
|
||||
// Mostrar error final después de agotar reintentos
|
||||
String finalMessage = "Error al reproducir: " + fullError;
|
||||
if (retryCount >= MAX_RETRIES) {
|
||||
finalMessage += "\n\nSe agotaron los reintentos (" + MAX_RETRIES + ").";
|
||||
}
|
||||
showError(finalMessage);
|
||||
}
|
||||
break;
|
||||
case Player.STATE_ENDED:
|
||||
Log.d(TAG, "Exo Event: ENDED");
|
||||
runOnUiThread(() -> {
|
||||
cancelStartupTimeout();
|
||||
finish();
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIsPlayingChanged(boolean isPlaying) {
|
||||
Log.d(TAG, "Exo Event: isPlaying=" + isPlaying);
|
||||
if (isPlaying) {
|
||||
runOnUiThread(() -> {
|
||||
playbackStarted = true;
|
||||
cancelStartupTimeout();
|
||||
showLoading(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerError(PlaybackException error) {
|
||||
String message = error.getMessage() != null
|
||||
? error.getMessage()
|
||||
: "code=" + error.errorCode;
|
||||
Log.e(TAG, "Exo Error: " + message, error);
|
||||
runOnUiThread(() -> {
|
||||
cancelStartupTimeout();
|
||||
handlePlaybackError("Error de reproducción Exo: " + message);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handlePlaybackError(String errorMsg) {
|
||||
if (tryAlternateSource("Falló la reproducción. " + errorMsg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String lower = errorMsg.toLowerCase();
|
||||
boolean isRetryableError =
|
||||
lower.contains("404") ||
|
||||
lower.contains("403") ||
|
||||
lower.contains("timeout") ||
|
||||
lower.contains("network") ||
|
||||
lower.contains("connection") ||
|
||||
lower.contains("source");
|
||||
|
||||
if (isRetryableError && retryCount < VlcPlayerConfig.MAX_RETRIES) {
|
||||
retryCount++;
|
||||
runOnUiThread(() -> {
|
||||
showLoading(true);
|
||||
errorMessage.setVisibility(View.VISIBLE);
|
||||
errorMessage.setText("Error de conexión. Reintentando... (" + retryCount + "/" + VlcPlayerConfig.MAX_RETRIES + ")");
|
||||
});
|
||||
|
||||
MediaItem mediaItem = MediaItem.fromUri(streamUrl);
|
||||
player.setMediaSource(buildMediaSource(mediaItem));
|
||||
player.prepare();
|
||||
player.setPlayWhenReady(true);
|
||||
setOverlayVisible(false);
|
||||
|
||||
} catch (Exception e) {
|
||||
showError("Error al inicializar reproductor: " + e.getMessage());
|
||||
mainHandler.postDelayed(() -> {
|
||||
if (lastStreamUrl != null) {
|
||||
startPlayback(lastStreamUrl);
|
||||
} else {
|
||||
loadChannel();
|
||||
}
|
||||
}, 1500);
|
||||
} else {
|
||||
String finalMessage = "Error al reproducir: " + errorMsg;
|
||||
if (retryCount >= VlcPlayerConfig.MAX_RETRIES) {
|
||||
finalMessage += "\n\nSe agotaron los reintentos (" + VlcPlayerConfig.MAX_RETRIES + ").";
|
||||
}
|
||||
showError(finalMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleStartupTimeout() {
|
||||
cancelStartupTimeout();
|
||||
startupTimeoutRunnable = () -> {
|
||||
if (!playbackStarted) {
|
||||
Log.w(TAG, "Timeout de inicio de reproducción");
|
||||
if (!tryAlternateSource("El canal no inició a tiempo. Probando fuente alterna...")) {
|
||||
handlePlaybackError("Timeout al iniciar stream");
|
||||
}
|
||||
}
|
||||
};
|
||||
mainHandler.postDelayed(startupTimeoutRunnable, STARTUP_TIMEOUT_MS);
|
||||
}
|
||||
|
||||
private void cancelStartupTimeout() {
|
||||
if (startupTimeoutRunnable != null) {
|
||||
mainHandler.removeCallbacks(startupTimeoutRunnable);
|
||||
startupTimeoutRunnable = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tryAlternateSource(String reason) {
|
||||
if (alternateSourceAttempted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String alternateUrl = buildAlternateGlobalUrl(currentChannelPageUrl);
|
||||
if (alternateUrl == null || alternateUrl.equals(currentChannelPageUrl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
alternateSourceAttempted = true;
|
||||
Log.w(TAG, "Probando fuente alterna: " + alternateUrl + " | motivo: " + reason);
|
||||
|
||||
showLoading(true);
|
||||
errorMessage.setVisibility(View.VISIBLE);
|
||||
errorMessage.setText("Problema con la fuente actual.\nProbando fuente alterna...");
|
||||
loadChannelFromPageUrl(alternateUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
private String buildAlternateGlobalUrl(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (url.contains("global2.php")) {
|
||||
return url.replace("global2.php", "global1.php");
|
||||
}
|
||||
if (url.contains("global1.php")) {
|
||||
return url.replace("global1.php", "global2.php");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showLoading(boolean show) {
|
||||
loadingIndicator.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
errorMessage.setVisibility(View.GONE);
|
||||
playerView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
playerView.setVisibility(View.VISIBLE);
|
||||
if (show) {
|
||||
setOverlayVisible(true);
|
||||
}
|
||||
@@ -227,68 +365,20 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void releasePlayer() {
|
||||
cancelStartupTimeout();
|
||||
playbackStarted = false;
|
||||
if (player != null) {
|
||||
player.release();
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private OkHttpClient provideOkHttpClient() {
|
||||
if (okHttpClient != null) {
|
||||
return okHttpClient;
|
||||
}
|
||||
|
||||
try {
|
||||
OkHttpClient bootstrap = new OkHttpClient.Builder()
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(true)
|
||||
.build();
|
||||
|
||||
DnsOverHttps dohDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get("https://dns.google/dns-query"))
|
||||
.bootstrapDnsHosts(
|
||||
InetAddress.getByName("8.8.8.8"),
|
||||
InetAddress.getByName("8.8.4.4"))
|
||||
.build();
|
||||
|
||||
okHttpClient = bootstrap.newBuilder()
|
||||
.dns(dohDns)
|
||||
.build();
|
||||
} catch (UnknownHostException e) {
|
||||
okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(20, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
return okHttpClient;
|
||||
playerView.setPlayer(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (player != null) {
|
||||
playerView.onResume();
|
||||
} else if (channelUrl != null) {
|
||||
loadChannel();
|
||||
if (player != null && !player.isPlaying()) {
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +386,7 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (player != null) {
|
||||
playerView.onResume();
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,14 +394,14 @@ public class PlayerActivity extends AppCompatActivity {
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (player != null) {
|
||||
playerView.onPause();
|
||||
player.pause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
releasePlayer();
|
||||
// Keep player for quick resume.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,53 +1,425 @@
|
||||
package com.streamplayer;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.Dns;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.dnsoverhttps.DnsOverHttps;
|
||||
|
||||
/**
|
||||
* Resuelve la URL real del stream extrayendo playbackURL de la página.
|
||||
* Utiliza NetworkUtils para configuración centralizada de DNS.
|
||||
* Utiliza DNS over HTTPS (Google + Cloudflare) para evitar bloqueos.
|
||||
* Soporta múltiples formatos de páginas y streams directos.
|
||||
* Soporta JWPlayer con DRM ClearKey.
|
||||
*/
|
||||
public final class StreamUrlResolver {
|
||||
|
||||
// Patrón para extraer la URL del stream directamente
|
||||
// Patrón original para streamtp10.com
|
||||
private static final Pattern PLAYBACK_URL_PATTERN =
|
||||
Pattern.compile("var\\s+playbackURL\\s*=\\s*[\"']([^\"']+)[\"']");
|
||||
|
||||
// Patrón para source src en tags video
|
||||
private static final Pattern VIDEO_SOURCE_PATTERN =
|
||||
Pattern.compile("<source[^>]+src=[\"']([^\"']+)[\"']");
|
||||
|
||||
// Patrón para URLs M3U8 en cualquier parte del HTML
|
||||
private static final Pattern M3U8_URL_PATTERN =
|
||||
Pattern.compile("(https?://[^\\s'\"<>]+\\.m3u8[^\\s'\"<>]*)");
|
||||
|
||||
// Patrón para URLs de stream en comillas dobles o simples
|
||||
private static final Pattern STREAM_URL_PATTERN =
|
||||
Pattern.compile("['\"](https?://[^'\"<>\\s]+?\\.(?:m3u8|mp4|ts)[^'\"<>\\s]*)['\"]");
|
||||
|
||||
// Patrón para file: o url: en JavaScript
|
||||
private static final Pattern JS_URL_PATTERN =
|
||||
Pattern.compile("(?:file|url|stream|source)\\s*[:=]\\s*[\"'](https?://[^\"']+)[\"']",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
|
||||
// Patrón para JWPlayer sources con "file": "url"
|
||||
private static final Pattern JWPLAYER_FILE_PATTERN =
|
||||
Pattern.compile("\"file\"\\s*:\\s*\"([^\"]+\\.m3u8[^\"]*)\"");
|
||||
|
||||
// Patrón para pares [indice, "base64"] del nuevo playbackURL ofuscado
|
||||
private static final Pattern OBFUSCATED_PAIR_PATTERN =
|
||||
Pattern.compile("\\[(\\d+)\\s*,\\s*[\"']([^\"']+)[\"']\\]");
|
||||
|
||||
// Patrón para k = fn1() + fn2()
|
||||
private static final Pattern OBFUSCATED_K_PATTERN =
|
||||
Pattern.compile("var\\s+k\\s*=\\s*([A-Za-z_$][\\w$]*)\\(\\)\\s*\\+\\s*([A-Za-z_$][\\w$]*)\\(\\)");
|
||||
|
||||
// Patrón para function fn() { return 12345; }
|
||||
private static final Pattern JS_RETURN_NUMBER_FUNCTION_PATTERN =
|
||||
Pattern.compile("function\\s+([A-Za-z_$][\\w$]*)\\s*\\(\\)\\s*\\{\\s*return\\s*(\\d+)\\s*;?\\s*\\}",
|
||||
Pattern.DOTALL);
|
||||
|
||||
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
|
||||
|
||||
private static final OkHttpClient CLIENT;
|
||||
|
||||
static {
|
||||
OkHttpClient client = null;
|
||||
try {
|
||||
final TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[]{};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.followRedirects(true)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
|
||||
.hostnameVerifier((hostname, session) -> true);
|
||||
|
||||
OkHttpClient bootstrap = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(10, TimeUnit.SECONDS)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
|
||||
.hostnameVerifier((hostname, session) -> true)
|
||||
.build();
|
||||
|
||||
final DnsOverHttps googleDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get("https://dns.google/dns-query"))
|
||||
.bootstrapDnsHosts(
|
||||
InetAddress.getByName("8.8.8.8"),
|
||||
InetAddress.getByName("8.8.4.4"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
final DnsOverHttps cloudflareDns = new DnsOverHttps.Builder()
|
||||
.client(bootstrap)
|
||||
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"))
|
||||
.bootstrapDnsHosts(
|
||||
InetAddress.getByName("1.1.1.1"),
|
||||
InetAddress.getByName("1.0.0.1"))
|
||||
.includeIPv6(false)
|
||||
.build();
|
||||
|
||||
builder.dns(hostname -> {
|
||||
try {
|
||||
List<InetAddress> result = googleDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
List<InetAddress> result = cloudflareDns.lookup(hostname);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
return Dns.SYSTEM.lookup(hostname);
|
||||
});
|
||||
|
||||
client = builder.build();
|
||||
} catch (Exception e) {
|
||||
client = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.followRedirects(true)
|
||||
.dns(Dns.SYSTEM)
|
||||
.build();
|
||||
}
|
||||
CLIENT = client;
|
||||
}
|
||||
|
||||
private StreamUrlResolver() {
|
||||
}
|
||||
|
||||
public static String resolve(String pageUrl) throws IOException {
|
||||
// Primero verificar si la URL ya parece ser un stream directo
|
||||
if (isDirectStreamUrl(pageUrl)) {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
String html = downloadPage(pageUrl);
|
||||
|
||||
// Buscar playbackURL directamente en el HTML
|
||||
Matcher matcher = PLAYBACK_URL_PATTERN.matcher(html);
|
||||
if (matcher.find()) {
|
||||
String url = matcher.group(1);
|
||||
if (url != null && !url.isEmpty() && url.startsWith("http")) {
|
||||
return url;
|
||||
}
|
||||
// Si el contenido ya parece ser un stream M3U8, retornarlo directamente
|
||||
if (html.startsWith("#EXTM3U") || html.startsWith("#EXT")) {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
// Intentar múltiples patrones de extracción
|
||||
String streamUrl = null;
|
||||
|
||||
// 1. Patrón original: var playbackURL = "..."
|
||||
streamUrl = extractWithPattern(html, PLAYBACK_URL_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 2. Patrón: <source src="...">
|
||||
streamUrl = extractWithPattern(html, VIDEO_SOURCE_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 3. Patrón: URLs M3U8 directas
|
||||
streamUrl = extractWithPattern(html, M3U8_URL_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 4. Patrón: URLs de stream en comillas
|
||||
streamUrl = extractWithPattern(html, STREAM_URL_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 5. Patrón: JavaScript file: / url: / stream:
|
||||
streamUrl = extractWithPattern(html, JS_URL_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 6. Patrón: JWPlayer "file": "url.m3u8" (para reproductores web y otros)
|
||||
streamUrl = extractWithPattern(html, JWPLAYER_FILE_PATTERN);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// 7. Nuevo formato ofuscado: playbackURL generado con atob + fromCharCode
|
||||
streamUrl = decodeObfuscatedPlaybackUrl(html);
|
||||
if (isValidStreamUrl(streamUrl)) {
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
// Si no encontramos nada con patrones, intentar usar la URL original
|
||||
// como stream directo (útil para URLs que ya son streams)
|
||||
if (html.contains(".m3u8") || html.contains("stream") || html.contains("video")) {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
// Último recurso: si la URL viene de sudamericaplay.com o similares,
|
||||
// intentar usarla directamente
|
||||
if (pageUrl.contains("sudamericaplay.com") ||
|
||||
pageUrl.contains("paramount")) {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
// Si no encontramos la URL, mostrar un fragmento del HTML para debug
|
||||
String preview = html.length() > 500 ? html.substring(0, 500) : html;
|
||||
throw new IOException("No se encontró la URL del stream en la página. Vista previa: " + preview);
|
||||
throw new IOException("No se encontró la URL del stream en la página. URL: " + pageUrl + ". Vista previa: " + preview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodifica páginas donde playbackURL se arma carácter por carácter con:
|
||||
* playbackURL += String.fromCharCode(parseInt(atob(v).replace(/\D/g,'')) - k)
|
||||
*/
|
||||
private static String decodeObfuscatedPlaybackUrl(String html) {
|
||||
if (html == null ||
|
||||
!html.contains("var playbackURL") ||
|
||||
!html.contains("playbackURL+=") ||
|
||||
!html.contains("String.fromCharCode") ||
|
||||
!html.contains("atob(")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int scriptStart = html.indexOf("var playbackURL");
|
||||
if (scriptStart < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int scriptEnd = html.indexOf("var p2pConfig", scriptStart);
|
||||
if (scriptEnd < 0) {
|
||||
scriptEnd = html.indexOf("</script>", scriptStart);
|
||||
}
|
||||
if (scriptEnd < 0 || scriptEnd <= scriptStart) {
|
||||
scriptEnd = Math.min(html.length(), scriptStart + 20000);
|
||||
}
|
||||
|
||||
String script = html.substring(scriptStart, scriptEnd);
|
||||
|
||||
Matcher kMatcher = OBFUSCATED_K_PATTERN.matcher(script);
|
||||
if (!kMatcher.find()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String functionA = kMatcher.group(1);
|
||||
String functionB = kMatcher.group(2);
|
||||
|
||||
Map<String, Long> functionValues = new HashMap<>();
|
||||
Matcher functionMatcher = JS_RETURN_NUMBER_FUNCTION_PATTERN.matcher(script);
|
||||
while (functionMatcher.find()) {
|
||||
try {
|
||||
functionValues.put(functionMatcher.group(1), Long.parseLong(functionMatcher.group(2)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
Long valueA = functionValues.get(functionA);
|
||||
Long valueB = functionValues.get(functionB);
|
||||
if (valueA == null || valueB == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
long k = valueA + valueB;
|
||||
|
||||
List<EncodedPair> pairs = new ArrayList<>();
|
||||
Matcher pairMatcher = OBFUSCATED_PAIR_PATTERN.matcher(script);
|
||||
while (pairMatcher.find()) {
|
||||
try {
|
||||
int index = Integer.parseInt(pairMatcher.group(1));
|
||||
pairs.add(new EncodedPair(index, pairMatcher.group(2)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (pairs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.sort(pairs, Comparator.comparingInt(pair -> pair.index));
|
||||
StringBuilder decoded = new StringBuilder(pairs.size());
|
||||
|
||||
for (EncodedPair pair : pairs) {
|
||||
byte[] decodedBytes;
|
||||
try {
|
||||
decodedBytes = Base64.decode(pair.encodedValue, Base64.DEFAULT);
|
||||
} catch (IllegalArgumentException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String decodedText = new String(decodedBytes, StandardCharsets.UTF_8);
|
||||
String digits = decodedText.replaceAll("\\D", "");
|
||||
if (digits.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long numericValue;
|
||||
try {
|
||||
numericValue = Long.parseLong(digits);
|
||||
} catch (NumberFormatException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long charCode = numericValue - k;
|
||||
if (charCode < 0 || charCode > Character.MAX_VALUE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
decoded.append((char) charCode);
|
||||
}
|
||||
|
||||
if (decoded.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String url = decoded.toString().trim()
|
||||
.replace("\\/", "/")
|
||||
.replace("\\u0026", "&")
|
||||
.replace("\\u002F", "/");
|
||||
|
||||
return isValidStreamUrl(url) ? url : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica si una URL parece ser un stream directo (M3U8, MP4, etc.)
|
||||
*/
|
||||
private static boolean isDirectStreamUrl(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String lower = url.toLowerCase();
|
||||
return lower.contains(".m3u8") ||
|
||||
lower.contains(".mpd") ||
|
||||
lower.contains("stream") && lower.contains(".php") == false ||
|
||||
lower.endsWith(".mp4") ||
|
||||
lower.endsWith(".ts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica si una URL extraída es válida
|
||||
*/
|
||||
private static boolean isValidStreamUrl(String url) {
|
||||
return url != null && !url.isEmpty() && url.startsWith("http");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrae la primera coincidencia de un patrón regex
|
||||
*/
|
||||
private static String extractWithPattern(String html, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(html);
|
||||
if (matcher.find()) {
|
||||
String url = matcher.group(1);
|
||||
// Limpiar URL de caracteres basura
|
||||
if (url != null) {
|
||||
url = url.trim();
|
||||
// Remover caracteres especiales al final
|
||||
url = url.replaceAll("[\"'<>\\s].*$", "");
|
||||
}
|
||||
return url;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intenta determinar el tipo de contenido del HTML
|
||||
*/
|
||||
private static String getContentTypeFromHtml(String html) {
|
||||
if (html == null || html.isEmpty()) {
|
||||
return "unknown";
|
||||
}
|
||||
String trimmed = html.trim();
|
||||
if (trimmed.startsWith("#EXTM3U") || trimmed.startsWith("#EXT")) {
|
||||
return "m3u8";
|
||||
}
|
||||
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
||||
return "json";
|
||||
}
|
||||
if (trimmed.startsWith("<")) {
|
||||
return "html";
|
||||
}
|
||||
return "text";
|
||||
}
|
||||
|
||||
private static String downloadPage(String pageUrl) throws IOException {
|
||||
Request request = new Request.Builder()
|
||||
.url(pageUrl)
|
||||
.header("User-Agent", NetworkUtils.getUserAgent())
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||
.header("Accept-Language", "es-ES,es;q=0.9,en;q=0.8")
|
||||
.header("Referer", "https://streamtp10.com/")
|
||||
.header("Referer", "http://streamtp10.com/")
|
||||
.build();
|
||||
|
||||
try (Response response = NetworkUtils.getClient().newCall(request).execute()) {
|
||||
try (Response response = CLIENT.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Error HTTP " + response.code() + " al cargar la página del stream");
|
||||
}
|
||||
@@ -58,4 +430,14 @@ public final class StreamUrlResolver {
|
||||
return response.body().string();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class EncodedPair {
|
||||
final int index;
|
||||
final String encodedValue;
|
||||
|
||||
EncodedPair(int index, String encodedValue) {
|
||||
this.index = index;
|
||||
this.encodedValue = encodedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ import java.lang.ref.WeakReference;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
@@ -63,11 +63,8 @@ public class UpdateManager {
|
||||
this.appContext = context.getApplicationContext();
|
||||
this.mainHandler = new Handler(Looper.getMainLooper());
|
||||
this.networkExecutor = Executors.newSingleThreadExecutor();
|
||||
this.httpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(20, TimeUnit.SECONDS)
|
||||
.callTimeout(25, TimeUnit.SECONDS)
|
||||
.build();
|
||||
// Usar NetworkUtils para obtener cliente con DNS over HTTPS configurado
|
||||
this.httpClient = NetworkUtils.getClient();
|
||||
}
|
||||
|
||||
public void checkForUpdates(UpdateCallback callback) {
|
||||
|
||||
66
app/src/main/java/com/streamplayer/VlcDrmManager.java
Normal file
66
app/src/main/java/com/streamplayer/VlcDrmManager.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.streamplayer;
|
||||
|
||||
import org.videolan.libvlc.Media;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handles DRM configuration for VLC Media Player
|
||||
* Supports ClearKey DRM for protected streaming services
|
||||
*/
|
||||
public class VlcDrmManager {
|
||||
|
||||
// ClearKey DRM configuration
|
||||
private static final String CLEARKEY_KEY_SYSTEM = "org.w3.clearkey";
|
||||
|
||||
/**
|
||||
* Configure ClearKey DRM for a Media object
|
||||
* @param media The VLC Media object
|
||||
* @param keyId The key ID (extracted from manifest or license server)
|
||||
* @param key The content key
|
||||
*/
|
||||
public static void configureClearKey(Media media, String keyId, String key) {
|
||||
if (media == null || keyId == null || key == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// VLC uses a specific format for ClearKey
|
||||
// Format: keyid:key
|
||||
String keyPair = keyId + ":" + key;
|
||||
media.addOption(":demux=avformat");
|
||||
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
|
||||
media.addOption(":key=" + keyPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure ClearKey DRM with multiple keys
|
||||
* @param media The VLC Media object
|
||||
* @param keys Map of keyId -> key pairs
|
||||
*/
|
||||
public static void configureClearKey(Media media, Map<String, String> keys) {
|
||||
if (media == null || keys == null || keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
media.addOption(":demux=avformat");
|
||||
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
|
||||
|
||||
for (Map.Entry<String, String> entry : keys.entrySet()) {
|
||||
String keyPair = entry.getKey() + ":" + entry.getValue();
|
||||
media.addOption(":key=" + keyPair);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Widevine DRM (for reference, if needed later)
|
||||
* VLC supports Widevine via specific options
|
||||
*/
|
||||
public static void configureWidevine(Media media, String drmServerUrl) {
|
||||
if (media == null || drmServerUrl == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
media.addOption(":drm=widevine");
|
||||
media.addOption(":aes-key=" + drmServerUrl);
|
||||
}
|
||||
}
|
||||
29
app/src/main/java/com/streamplayer/VlcPlayerConfig.java
Normal file
29
app/src/main/java/com/streamplayer/VlcPlayerConfig.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.streamplayer;
|
||||
|
||||
/**
|
||||
* Configuration constants for VLC Player
|
||||
*/
|
||||
public class VlcPlayerConfig {
|
||||
|
||||
// Network caching (ms)
|
||||
public static final int NETWORK_CACHING = 1500;
|
||||
|
||||
// Live streaming caching (ms)
|
||||
public static final int LIVE_CACHING = 5000;
|
||||
|
||||
// User Agent
|
||||
public static final String USER_AGENT =
|
||||
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
|
||||
|
||||
// Hardware acceleration
|
||||
public static final String HW_ACCELERATION = "automatic";
|
||||
|
||||
// Chroma format
|
||||
public static final String CHROMA = "RV32";
|
||||
|
||||
// Audio output
|
||||
public static final String AUDIO_OUTPUT = "opensles";
|
||||
|
||||
// Maximum retries for playback
|
||||
public static final int MAX_RETRIES = 3;
|
||||
}
|
||||
@@ -11,8 +11,10 @@
|
||||
android:id="@+id/player_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:resize_mode="fill"
|
||||
app:use_controller="true" />
|
||||
android:keepScreenOn="true"
|
||||
app:show_buffering="never"
|
||||
app:surface_type="surface_view"
|
||||
app:use_controller="false" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/player_toolbar"
|
||||
|
||||
@@ -12,6 +12,7 @@ allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://get.videolan.org/android/maven2/" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"versionCode": 100300,
|
||||
"versionName": "10.0.3",
|
||||
"minSupportedVersionCode": 91000,
|
||||
"versionCode": 100110,
|
||||
"versionName": "10.1.10",
|
||||
"minSupportedVersionCode": 0,
|
||||
"forceUpdate": false,
|
||||
"downloadUrl": "https://gitea.cbcren.online/renato97/app/releases/download/v10.0.3/StreamPlayer-v10.0.3.apk",
|
||||
"fileName": "StreamPlayer-v10.0.3.apk",
|
||||
"sizeBytes": 0,
|
||||
"notes": "StreamPlayer v10.0.3\n\nNovedades:\n- Fix: Evasión de bloqueos regionales mediante DNS de Google (DoH)\n- Corrección de error 'No se encontró la clave del stream'"
|
||||
"downloadUrl": "http://gitea.cbcren.online/renato97/app/releases/download/v10.1.10/StreamPlayer-v10.1.10-debug.apk",
|
||||
"fileName": "StreamPlayer-v10.1.10-debug.apk",
|
||||
"sizeBytes": 9113609,
|
||||
"notes": "Cambiar a HTTP para evitar errores de certificado"
|
||||
}
|
||||
Reference in New Issue
Block a user