Allow media to be played automatically

This commit is contained in:
Javi Rueda 2021-02-25 17:27:16 +01:00
parent 2761857fe8
commit f9a65d4277
4 changed files with 18 additions and 5 deletions

View file

@ -336,6 +336,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
// preference keys
public static final String PREFERENCE_KEY_BACKGROUND_PLAYBACK = "io.lbry.browser.preference.userinterface.BackgroundPlayback";
public static final String PREFERENCE_KEY_MEDIA_AUTOPLAY = "io.lbry.browser.preference.userinterface.MediaAutoplay";
public static final String PREFERENCE_KEY_DARK_MODE = "io.lbry.browser.preference.userinterface.DarkMode";
public static final String PREFERENCE_KEY_SHOW_MATURE_CONTENT = "io.lbry.browser.preference.userinterface.ShowMatureContent";
public static final String PREFERENCE_KEY_SHOW_URL_SUGGESTIONS = "io.lbry.browser.preference.userinterface.UrlSuggestions";
@ -680,6 +681,11 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
return sp.getBoolean(PREFERENCE_KEY_BACKGROUND_PLAYBACK, true);
}
public boolean isMediaAutoplayEnabled() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
return sp.getBoolean(PREFERENCE_KEY_MEDIA_AUTOPLAY, true);
}
public boolean initialSubscriptionMergeDone() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
return sp.getBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_SUBSCRIPTION_MERGE_DONE, false);

View file

@ -12,7 +12,6 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.format.DateUtils;
@ -98,6 +97,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -284,7 +284,7 @@ public class FileViewFragment extends BaseFragment implements
fileViewPlayerListener = new Player.EventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
public void onPlaybackStateChanged(@Player.State int playbackState) {
if (playbackState == Player.STATE_READY) {
elapsedDuration = MainActivity.appPlayer.getCurrentPosition();
totalDuration = MainActivity.appPlayer.getDuration() < 0 ? 0 : MainActivity.appPlayer.getDuration();
@ -303,7 +303,7 @@ public class FileViewFragment extends BaseFragment implements
hideBuffering();
if (loadingNewClaim) {
MainActivity.appPlayer.setPlayWhenReady(true);
MainActivity.appPlayer.setPlayWhenReady(Objects.requireNonNull((MainActivity) (getActivity())).isMediaAutoplayEnabled());
loadingNewClaim = false;
}
} else if (playbackState == Player.STATE_BUFFERING) {
@ -1762,7 +1762,7 @@ public class FileViewFragment extends BaseFragment implements
((MainActivity) context).setNowPlayingClaim(claim, currentUrl);
}
MainActivity.appPlayer.setPlayWhenReady(true);
MainActivity.appPlayer.setPlayWhenReady(Objects.requireNonNull((MainActivity) (getActivity())).isMediaAutoplayEnabled());
String userAgent = Util.getUserAgent(context, getString(R.string.app_name));
String mediaSourceUrl = getStreamingUrl();
MediaSource mediaSource = new ProgressiveMediaSource.Factory(
@ -1770,7 +1770,8 @@ public class FileViewFragment extends BaseFragment implements
new DefaultExtractorsFactory()
).setLoadErrorHandlingPolicy(new StreamLoadErrorPolicy()).createMediaSource(Uri.parse(mediaSourceUrl));
MainActivity.appPlayer.prepare(mediaSource, true, true);
MainActivity.appPlayer.setMediaSource(mediaSource, true);
MainActivity.appPlayer.prepare();
}
}
}

View file

@ -247,6 +247,7 @@
<string name="user_interface">Content &amp; User interface</string>
<string name="other">Other</string>
<string name="enable_background_playback">Enable background playback</string>
<string name="enable_autoplay">Autoplay media files</string>
<string name="enable_dark_mode">Enable dark theme</string>
<string name="show_mature_content">Show mature content</string>
<string name="show_url_suggestions">Show URL suggestions</string>

View file

@ -10,6 +10,11 @@
app:defaultValue="true"
app:title="@string/enable_background_playback"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
app:key="io.lbry.browser.preference.userinterface.MediaAutoplay"
app:defaultValue="true"
app:title="@string/enable_autoplay"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
app:key="io.lbry.browser.preference.userinterface.DarkMode"
app:title="@string/enable_dark_mode"