Skip to content

Commit

Permalink
Merge pull request TeamNewPipe#2697 from Redirion/exoplayer2105
Browse files Browse the repository at this point in the history
Update to ExoPlayer 2.10.5
  • Loading branch information
TobiGr authored Oct 10, 2019
2 parents a02e12a + b2b32ce commit 28ed987
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 121 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ android {

ext {
androidxLibVersion = '1.0.0'
exoPlayerLibVersion = '2.9.6' //2.10.5
exoPlayerLibVersion = '2.10.5'
roomDbLibVersion = '2.1.0'
leakCanaryLibVersion = '1.5.4' //1.6.1
okHttpLibVersion = '3.12.1'
okHttpLibVersion = '3.12.5' //3.12.6
icepickLibVersion = '3.2.0'
stethoLibVersion = '1.5.0'
}
Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import com.google.android.material.navigation.NavigationView;
import androidx.fragment.app.Fragment;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -49,6 +39,17 @@
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;

import com.google.android.material.navigation.NavigationView;

import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
Expand Down Expand Up @@ -361,7 +362,7 @@ protected void onResume() {

// close drawer on return, and don't show animation, so its looks like the drawer isn't open
// when the user returns to MainActivity
drawer.closeDrawer(Gravity.START, false);
drawer.closeDrawer(GravityCompat.START, false);
try {
String selectedServiceName = NewPipe.getService(
ServiceHelper.getSelectedServiceId(this)).getServiceInfo().getName();
Expand Down
23 changes: 12 additions & 11 deletions app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
package org.schabi.newpipe.fragments;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -18,6 +9,17 @@
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import org.schabi.newpipe.BaseFragment;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
Expand Down Expand Up @@ -111,8 +113,7 @@ public void onResume() {
public void onDestroy() {
super.onDestroy();
tabsManager.unsetSavedTabsListener();
pagerAdapter = null;
viewPager.setAdapter(pagerAdapter);
if (viewPager != null) viewPager.setAdapter(null);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.schabi.newpipe.fragments.list;

import android.os.Bundle;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.util.Constants;
Expand Down Expand Up @@ -61,8 +62,10 @@ public void onResume() {
@Override
public void onDestroy() {
super.onDestroy();
if (currentWorker != null) currentWorker.dispose();
currentWorker = null;
if (currentWorker != null) {
currentWorker.dispose();
currentWorker = null;
}
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
Expand Down Expand Up @@ -209,7 +210,7 @@ public void onReceive(Context context, Intent intent) {
this.databaseUpdateReactor = new CompositeDisposable();

final String userAgent = Downloader.USER_AGENT;
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build();
this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);

final TrackSelection.Factory trackSelectionFactory = PlayerHelper.getQualitySelector(context);
Expand Down Expand Up @@ -1193,10 +1194,7 @@ public boolean isLive() {
}

public boolean isPlaying() {
if (simpleExoPlayer == null) return false;
final int state = simpleExoPlayer.getPlaybackState();
return (state == Player.STATE_READY || state == Player.STATE_BUFFERING)
&& simpleExoPlayer.getPlayWhenReady();
return simpleExoPlayer != null && simpleExoPlayer.isPlaying();
}

@Player.RepeatMode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.schabi.newpipe.player.helper;

import android.content.Context;
import androidx.annotation.NonNull;
import android.util.Log;

import androidx.annotation.NonNull;

import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
Expand Down Expand Up @@ -54,7 +56,7 @@ private CacheFactory(@NonNull final Context context,

if (cache == null) {
final LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);
cache = new SimpleCache(cacheDir, evictor);
cache = new SimpleCache(cacheDir, evictor, new ExoDatabaseProvider(context));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import android.content.Context;
import android.content.Intent;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaSessionCompat;
import android.view.KeyEvent;

import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
Expand All @@ -27,10 +28,10 @@ public MediaSessionManager(@NonNull final Context context,
this.mediaSession = new MediaSessionCompat(context, TAG);
this.mediaSession.setActive(true);

this.sessionConnector = new MediaSessionConnector(mediaSession,
new PlayQueuePlaybackController(callback));
this.sessionConnector = new MediaSessionConnector(mediaSession);
this.sessionConnector.setControlDispatcher(new PlayQueuePlaybackController(callback));
this.sessionConnector.setQueueNavigator(new PlayQueueNavigator(mediaSession, callback));
this.sessionConnector.setPlayer(player, null);
this.sessionConnector.setPlayer(player);
}

@Nullable
Expand All @@ -43,7 +44,7 @@ public KeyEvent handleMediaButtonIntent(final Intent intent) {
* Should be called on player destruction to prevent leakage.
* */
public void dispose() {
this.sessionConnector.setPlayer(null, null);
this.sessionConnector.setPlayer(null);
this.sessionConnector.setQueueNavigator(null);
this.mediaSession.setActive(false);
this.mediaSession.release();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.schabi.newpipe.player.helper;

import android.content.Context;

import androidx.annotation.NonNull;

import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
Expand Down Expand Up @@ -64,12 +65,12 @@ public DashMediaSource.Factory getDashMediaSourceFactory() {
cacheDataSourceFactory), cacheDataSourceFactory);
}

public ExtractorMediaSource.Factory getExtractorMediaSourceFactory() {
return new ExtractorMediaSource.Factory(cacheDataSourceFactory)
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
}

public ExtractorMediaSource.Factory getExtractorMediaSourceFactory(@NonNull final String key) {
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory(@NonNull final String key) {
return getExtractorMediaSourceFactory().setCustomCacheKey(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import android.os.Bundle;
import android.os.ResultReceiver;
import android.support.v4.media.session.MediaSessionCompat;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.support.v4.media.session.MediaSessionCompat;

import com.google.android.exoplayer2.ControlDispatcher;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import com.google.android.exoplayer2.util.Util;
Expand Down Expand Up @@ -63,17 +65,17 @@ public long getActiveQueueItemId(@Nullable Player player) {
}

@Override
public void onSkipToPrevious(Player player) {
public void onSkipToPrevious(Player player, ControlDispatcher controlDispatcher) {
callback.onSkipToPrevious();
}

@Override
public void onSkipToQueueItem(Player player, long id) {
public void onSkipToQueueItem(Player player, ControlDispatcher controlDispatcher, long id) {
callback.onSkipToIndex((int) id);
}

@Override
public void onSkipToNext(Player player) {
public void onSkipToNext(Player player, ControlDispatcher controlDispatcher) {
callback.onSkipToNext();
}

Expand All @@ -100,12 +102,7 @@ private void publishFloatingQueueWindow() {
}

@Override
public String[] getCommands() {
return new String[0];
}

@Override
public void onCommand(Player player, String command, Bundle extras, ResultReceiver cb) {

public boolean onCommand(Player player, ControlDispatcher controlDispatcher, String command, Bundle extras, ResultReceiver cb) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.schabi.newpipe.player.mediasession;

import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.mediasession.DefaultPlaybackController;

public class PlayQueuePlaybackController extends DefaultPlaybackController {
public class PlayQueuePlaybackController extends DefaultControlDispatcher {
private final MediaSessionCallback callback;

public PlayQueuePlaybackController(final MediaSessionCallback callback) {
Expand All @@ -12,12 +12,12 @@ public PlayQueuePlaybackController(final MediaSessionCallback callback) {
}

@Override
public void onPlay(Player player) {
callback.onPlay();
}

@Override
public void onPause(Player player) {
callback.onPause();
public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
if (playWhenReady) {
callback.onPlay();
} else {
callback.onPause();
}
return true;
}
}
Loading

0 comments on commit 28ed987

Please sign in to comment.