mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-31 02:44:53 +01:00
Send Authorization header to be able to stream password protected media (#4843)
This commit is contained in:
parent
08d1400951
commit
5be6f5feba
@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.playback;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
@ -28,8 +29,10 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
|||||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.ClientConfig;
|
import de.danoeh.antennapod.core.ClientConfig;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.core.service.download.HttpDownloader;
|
||||||
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
@ -184,14 +187,22 @@ public class ExoPlayerWrapper implements IPlayer {
|
|||||||
exoPlayer.setAudioAttributes(b.build());
|
exoPlayer.setAudioAttributes(b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setDataSource(String s, String user, String password)
|
||||||
public void setDataSource(String s) throws IllegalArgumentException, IllegalStateException {
|
throws IllegalArgumentException, IllegalStateException {
|
||||||
Log.d(TAG, "setDataSource: " + s);
|
Log.d(TAG, "setDataSource: " + s);
|
||||||
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
|
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(
|
||||||
ClientConfig.USER_AGENT, null,
|
ClientConfig.USER_AGENT, null,
|
||||||
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(user) && !TextUtils.isEmpty(password)) {
|
||||||
|
httpDataSourceFactory.getDefaultRequestProperties().set("Authorization",
|
||||||
|
HttpDownloader.encodeCredentials(
|
||||||
|
user,
|
||||||
|
password,
|
||||||
|
"ISO-8859-1"));
|
||||||
|
}
|
||||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
|
||||||
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
|
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
|
||||||
extractorsFactory.setConstantBitrateSeekingEnabled(true);
|
extractorsFactory.setConstantBitrateSeekingEnabled(true);
|
||||||
@ -199,6 +210,11 @@ public class ExoPlayerWrapper implements IPlayer {
|
|||||||
mediaSource = f.createMediaSource(Uri.parse(s));
|
mediaSource = f.createMediaSource(Uri.parse(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDataSource(String s) throws IllegalArgumentException, IllegalStateException {
|
||||||
|
setDataSource(s, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDisplay(SurfaceHolder sh) {
|
public void setDisplay(SurfaceHolder sh) {
|
||||||
exoPlayer.setVideoSurfaceHolder(sh);
|
exoPlayer.setVideoSurfaceHolder(sh);
|
||||||
|
@ -260,7 +260,16 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||||||
callback.onMediaChanged(false);
|
callback.onMediaChanged(false);
|
||||||
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
|
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
|
||||||
if (stream) {
|
if (stream) {
|
||||||
mediaPlayer.setDataSource(media.getStreamUrl());
|
if (playable instanceof FeedMedia) {
|
||||||
|
FeedMedia feedMedia = (FeedMedia) playable;
|
||||||
|
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
|
||||||
|
mediaPlayer.setDataSource(
|
||||||
|
media.getStreamUrl(),
|
||||||
|
preferences.getUsername(),
|
||||||
|
preferences.getPassword());
|
||||||
|
} else {
|
||||||
|
mediaPlayer.setDataSource(media.getStreamUrl());
|
||||||
|
}
|
||||||
} else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) {
|
} else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) {
|
||||||
mediaPlayer.setDataSource(media.getLocalMediaUrl());
|
mediaPlayer.setDataSource(media.getLocalMediaUrl());
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,6 +10,7 @@ import org.antennapod.audio.MediaPlayer;
|
|||||||
|
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -64,4 +65,9 @@ public class AudioPlayer extends MediaPlayer implements IPlayer {
|
|||||||
public int getSelectedAudioTrack() {
|
public int getSelectedAudioTrack() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDataSource(String streamUrl, String username, String password) throws IOException {
|
||||||
|
setDataSource(streamUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public interface IPlayer {
|
|||||||
void setDataSource(String path) throws IllegalStateException, IOException,
|
void setDataSource(String path) throws IllegalStateException, IOException,
|
||||||
IllegalArgumentException, SecurityException;
|
IllegalArgumentException, SecurityException;
|
||||||
|
|
||||||
|
void setDataSource(String streamUrl, String username, String password) throws IOException;
|
||||||
|
|
||||||
void setDisplay(SurfaceHolder sh);
|
void setDisplay(SurfaceHolder sh);
|
||||||
|
|
||||||
void setPlaybackParams(float speed, boolean skipSilence);
|
void setPlaybackParams(float speed, boolean skipSilence);
|
||||||
|
@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.util.playback;
|
|||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -52,4 +53,9 @@ public class VideoPlayer extends MediaPlayer implements IPlayer {
|
|||||||
public int getSelectedAudioTrack() {
|
public int getSelectedAudioTrack() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDataSource(String streamUrl, String username, String password) throws IOException {
|
||||||
|
setDataSource(streamUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user