diff options
Diffstat (limited to 'app/src/main/java/github/daneren2005')
15 files changed, 279 insertions, 23 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java index 0b10d7fb..a1c5ceef 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -250,12 +250,20 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte return; } - populateTabs(); getImageLoader().onUIVisible(); UpdateView.addActiveActivity(); } @Override + protected void onResume() { + super.onResume(); + + // If this is in onStart is causes crashes when rotating screen in offline mode + // Actual root cause of error is `drawerItemSelected(newFragment);` in the offline mode branch of code + populateTabs(); + } + + @Override protected void onStop() { super.onStop(); diff --git a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java index e41a9503..5852210e 100644 --- a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java +++ b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java @@ -251,4 +251,9 @@ public class ServerInfo implements Serializable { public static boolean hasNewestPodcastEpisodes(Context context) { return ServerInfo.checkServerVersion(context, "1.13"); } + + public static boolean canRescanServer(Context context) { + return ServerInfo.isMadsonic(context) || + (ServerInfo.isStockSubsonic(context) && ServerInfo.checkServerVersion(context, "1.15")); + } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java index 8c2fa4bf..82e50b76 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -67,8 +67,8 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { onFinishSetupOptionsMenu(menu); try { - if (!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) { - menu.setGroupVisible(R.id.madsonic, false); + if (!ServerInfo.canRescanServer(context) || !UserUtil.isCurrentAdmin()) { + menu.setGroupVisible(R.id.rescan_server, false); } } catch(Exception e) { Log.w(TAG, "Error on setting madsonic invisible", e); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 28cf9911..5cb413fe 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -1,5 +1,8 @@ package github.daneren2005.dsub.fragments; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.support.v7.app.AlertDialog; import android.content.DialogInterface; import android.content.res.Resources; @@ -342,7 +345,24 @@ public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> { private void syncPlaylist(Playlist playlist) { SyncUtil.addSyncedPlaylist(context, playlist.getId()); - downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); + + boolean syncImmediately; + if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_SYNC_WIFI, true)) { + ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = manager.getActiveNetworkInfo(); + + if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + syncImmediately = true; + } else { + syncImmediately = false; + } + } else { + syncImmediately = true; + } + + if(syncImmediately) { + downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); + } } private void stopSyncPlaylist(final Playlist playlist) { diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java index 584a205a..fa2ca340 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SettingsFragment.java @@ -59,6 +59,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.LoadingTask; +import github.daneren2005.dsub.util.MediaRouteManager; import github.daneren2005.dsub.util.SyncUtil; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.CacheLocationPreference; @@ -200,6 +201,18 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared ActivityCompat.requestPermissions(context, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION }, SubsonicActivity.PERMISSIONS_REQUEST_LOCATION); } } + } else if(Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED.equals(key)) { + DownloadService downloadService = DownloadService.getInstance(); + if(downloadService != null) { + MediaRouteManager mediaRouter = downloadService.getMediaRouter(); + + Boolean enabled = sharedPreferences.getBoolean(key, true); + if (enabled) { + mediaRouter.addDLNAProvider(); + } else { + mediaRouter.removeDLNAProvider(); + } + } } scheduleBackup(); diff --git a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java index 0f6975ba..0ee16723 100644 --- a/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java +++ b/app/src/main/java/github/daneren2005/dsub/provider/DLNARouteProvider.java @@ -71,6 +71,7 @@ public class DLNARouteProvider extends MediaRouteProvider { private List<String> removing = new ArrayList<String>(); private AndroidUpnpService dlnaService; private ServiceConnection dlnaServiceConnection; + private RegistryListener registryListener; private boolean searchOnConnect = false; public DLNARouteProvider(Context context) { @@ -84,7 +85,7 @@ public class DLNARouteProvider extends MediaRouteProvider { @Override public void onServiceConnected(ComponentName name, IBinder service) { dlnaService = (AndroidUpnpService) service; - dlnaService.getRegistry().addListener(new RegistryListener() { + dlnaService.getRegistry().addListener(registryListener = new RegistryListener() { @Override public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice remoteDevice) { @@ -142,6 +143,7 @@ public class DLNARouteProvider extends MediaRouteProvider { @Override public void onServiceDisconnected(ComponentName name) { dlnaService = null; + registryListener = null; } }; @@ -290,6 +292,17 @@ public class DLNARouteProvider extends MediaRouteProvider { } } + public void destroy() { + if(dlnaService != null) { + dlnaService.getRegistry().removeListener(registryListener); + registryListener = null; + } + + if(dlnaServiceConnection != null) { + getContext().getApplicationContext().unbindService(dlnaServiceConnection); + } + } + private class DLNARouteController extends RouteController { private DLNADevice device; diff --git a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java index ece8ee95..35f6d37a 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java @@ -21,6 +21,7 @@ package github.daneren2005.dsub.service; import android.annotation.TargetApi; import android.content.Intent; import android.media.MediaDescription; +import android.media.MediaMetadata; import android.media.browse.MediaBrowser; import android.os.Build; import android.os.Bundle; @@ -33,8 +34,11 @@ import java.util.ArrayList; import java.util.List; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.Indexes; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.MusicDirectory.Entry; +import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.domain.PodcastChannel; import github.daneren2005.dsub.domain.PodcastEpisode; @@ -58,6 +62,8 @@ public class AutoMediaBrowserService extends MediaBrowserService { private static final String PODCAST_PREFIX = "po-"; private static final String ALBUM_TYPE_PREFIX = "ty-"; private static final String MUSIC_DIRECTORY_PREFIX = "md-"; + private static final String MUSIC_FOLDER_PREFIX = "mf-"; + private static final String MUSIC_DIRECTORY_CONTENTS_PREFIX = "mdc-"; private DownloadService downloadService; private Handler handler = new Handler(); @@ -89,6 +95,12 @@ public class AutoMediaBrowserService extends MediaBrowserService { getPlayOptions(result, id, Constants.INTENT_EXTRA_NAME_ID); } else if(BROWSER_LIBRARY.equals(parentId)) { getLibrary(result); + } else if(parentId.startsWith(MUSIC_FOLDER_PREFIX)) { + String id = parentId.substring(MUSIC_FOLDER_PREFIX.length()); + getIndexes(result, id); + } else if(parentId.startsWith(MUSIC_DIRECTORY_CONTENTS_PREFIX)) { + String id = parentId.substring(MUSIC_DIRECTORY_CONTENTS_PREFIX.length()); + getMusicDirectory(result, id); } else if(BROWSER_PLAYLISTS.equals(parentId)) { getPlaylists(result); } else if(parentId.startsWith(PLAYLIST_PREFIX)) { @@ -115,10 +127,10 @@ public class AutoMediaBrowserService extends MediaBrowserService { .setMediaId(BROWSER_ALBUM_LISTS); mediaItems.add(new MediaBrowser.MediaItem(albumLists.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE)); - /*MediaDescription.Builder library = new MediaDescription.Builder(); + MediaDescription.Builder library = new MediaDescription.Builder(); library.setTitle(downloadService.getString(R.string.button_bar_browse)) .setMediaId(BROWSER_LIBRARY); - mediaItems.add(new MediaBrowser.MediaItem(library.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));*/ + mediaItems.add(new MediaBrowser.MediaItem(library.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE)); MediaDescription.Builder playlists = new MediaDescription.Builder(); playlists.setTitle(downloadService.getString(R.string.button_bar_playlists)) @@ -218,8 +230,106 @@ public class AutoMediaBrowserService extends MediaBrowserService { result.detach(); } - private void getLibrary(Result<List<MediaBrowser.MediaItem>> result) { + private void getLibrary(final Result<List<MediaBrowser.MediaItem>> result) { + new SilentServiceTask<List<MusicFolder>>(downloadService) { + @Override + protected List<MusicFolder> doInBackground(MusicService musicService) throws Throwable { + return musicService.getMusicFolders(false, downloadService, null); + } + + @Override + protected void done(List<MusicFolder> folders) { + List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + + for(MusicFolder folder: folders) { + MediaDescription description = new MediaDescription.Builder() + .setTitle(folder.getName()) + .setMediaId(MUSIC_FOLDER_PREFIX + folder.getId()) + .build(); + + mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE)); + } + + result.sendResult(mediaItems); + } + }.execute(); + + result.detach(); + } + private void getIndexes(final Result<List<MediaBrowser.MediaItem>> result, final String musicFolderId) { + new SilentServiceTask<Indexes>(downloadService) { + @Override + protected Indexes doInBackground(MusicService musicService) throws Throwable { + return musicService.getIndexes(musicFolderId, false, downloadService, null); + } + + @Override + protected void done(Indexes indexes) { + List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + + // music directories + for(Artist artist : indexes.getArtists()) { + MediaDescription description = new MediaDescription.Builder() + .setTitle(artist.getName()) + .setMediaId(MUSIC_DIRECTORY_CONTENTS_PREFIX + artist.getId()) + .build(); + + mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE)); + } + + // music files + for(Entry entry: indexes.getEntries()) { + MediaDescription description = new MediaDescription.Builder() + .setTitle(entry.getTitle()) + .setMediaId(MUSIC_DIRECTORY_PREFIX + entry.getId()) + .build(); + mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE)); + } + + result.sendResult(mediaItems); + } + }.execute(); + + result.detach(); + } + + private void getMusicDirectory(final Result<List<MediaBrowser.MediaItem>> result, final String musicDirectoryId) { + new SilentServiceTask<MusicDirectory>(downloadService) { + @Override + protected MusicDirectory doInBackground(MusicService musicService) throws Throwable { + return musicService.getMusicDirectory(musicDirectoryId, "", false, downloadService, null); + } + + @Override + protected void done(MusicDirectory directory) { + List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + + addPlayOptions(mediaItems, musicDirectoryId, Constants.INTENT_EXTRA_NAME_ID); + + for(Entry entry : directory.getChildren()) { + MediaDescription description; + if (entry.isDirectory()) { + // browse deeper + description = new MediaDescription.Builder() + .setTitle(entry.getTitle()) + .setMediaId(MUSIC_DIRECTORY_CONTENTS_PREFIX + entry.getId()) + .build(); + } else { + // playback options for a single item + description = new MediaDescription.Builder() + .setTitle(entry.getTitle()) + .setMediaId(MUSIC_DIRECTORY_PREFIX + entry.getId()) + .build(); + } + + mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE)); + } + result.sendResult(mediaItems); + } + }.execute(); + + result.detach(); } private void getPlaylists(final Result<List<MediaBrowser.MediaItem>> result) { @@ -341,10 +451,8 @@ public class AutoMediaBrowserService extends MediaBrowserService { result.detach(); } - - private void getPlayOptions(Result<List<MediaBrowser.MediaItem>> result, String id, String idConstant) { - List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + private void addPlayOptions(List<MediaBrowser.MediaItem> mediaItems, String id, String idConstant) { Bundle playAllExtras = new Bundle(); playAllExtras.putString(idConstant, id); @@ -373,6 +481,12 @@ public class AutoMediaBrowserService extends MediaBrowserService { .setMediaId("playLast-" + id) .setExtras(playLastExtras); mediaItems.add(new MediaBrowser.MediaItem(playLast.build(), MediaBrowser.MediaItem.FLAG_PLAYABLE)); + } + + private void getPlayOptions(Result<List<MediaBrowser.MediaItem>> result, String id, String idConstant) { + List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>(); + + addPlayOptions(mediaItems, id, idConstant); result.sendResult(mediaItems); } diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index e23995f2..636745d6 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1665,6 +1665,9 @@ public class DownloadService extends Service { return controller; } + public MediaRouteManager getMediaRouter() { + return mediaRouter; + } public MediaRouteSelector getRemoteSelector() { return mediaRouter.getSelector(); } diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index 1aa1d212..657ac4a9 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -177,7 +177,17 @@ public class RESTMusicService implements MusicService { @Override public void startRescan(Context context, ProgressListener listener) throws Exception { - Reader reader = getReader(context, listener, "startRescan"); + String startMethod = ServerInfo.isMadsonic(context, getInstance(context)) ? "startRescan" : "startScan"; + String refreshMethod = null; + if(ServerInfo.isMadsonic(context, getInstance(context))) { + startMethod = "startRescan"; + refreshMethod = "scanstatus"; + } else { + startMethod = "startScan"; + refreshMethod = "getScanStatus"; + } + + Reader reader = getReader(context, listener, startMethod); try { new ErrorParser(context, getInstance(context)).parse(reader); } finally { @@ -187,7 +197,7 @@ public class RESTMusicService implements MusicService { // Now check if still running boolean done = false; while(!done) { - reader = getReader(context, null, "scanstatus"); + reader = getReader(context, null, refreshMethod); try { boolean running = new ScanStatusParser(context, getInstance(context)).parse(reader, listener); if(running) { diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/ScanStatusParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/ScanStatusParser.java index ffb3ba05..acd00661 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/parser/ScanStatusParser.java +++ b/app/src/main/java/github/daneren2005/dsub/service/parser/ScanStatusParser.java @@ -21,6 +21,7 @@ import org.xmlpull.v1.XmlPullParser; import java.io.Reader; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.util.ProgressListener; public class ScanStatusParser extends AbstractParser { @@ -32,14 +33,23 @@ public class ScanStatusParser extends AbstractParser { public boolean parse(Reader reader, ProgressListener progressListener) throws Exception { init(reader); - Boolean started = null; + String scanName, scanningName; + if(ServerInfo.isMadsonic(context, instance)) { + scanName = "status"; + scanningName = "started"; + } else { + scanName = "scanStatus"; + scanningName = "scanning"; + } + + Boolean scanning = null; int eventType; do { eventType = nextParseEvent(); if (eventType == XmlPullParser.START_TAG) { String name = getElementName(); - if("status".equals(name)) { - started = getBoolean("started"); + if(scanName.equals(name)) { + scanning = getBoolean(scanningName); String msg = context.getResources().getString(R.string.parser_scan_count, getInteger("count")); progressListener.updateProgress(msg); @@ -51,6 +61,6 @@ public class ScanStatusParser extends AbstractParser { validate(); - return started != null && started; + return scanning != null && scanning; } }
\ No newline at end of file diff --git a/app/src/main/java/github/daneren2005/dsub/updates/Updater.java b/app/src/main/java/github/daneren2005/dsub/updates/Updater.java index bc053b1e..2dabb624 100644 --- a/app/src/main/java/github/daneren2005/dsub/updates/Updater.java +++ b/app/src/main/java/github/daneren2005/dsub/updates/Updater.java @@ -48,6 +48,7 @@ public class Updater { this.context = context; List<Updater> updaters = new ArrayList<Updater>(); updaters.add(new UpdaterSongPress()); + updaters.add(new UpdaterNoDLNA()); SharedPreferences prefs = Util.getPreferences(context); int lastVersion = prefs.getInt(Constants.LAST_VERSION, 0); diff --git a/app/src/main/java/github/daneren2005/dsub/updates/UpdaterNoDLNA.java b/app/src/main/java/github/daneren2005/dsub/updates/UpdaterNoDLNA.java new file mode 100644 index 00000000..a060c4fd --- /dev/null +++ b/app/src/main/java/github/daneren2005/dsub/updates/UpdaterNoDLNA.java @@ -0,0 +1,41 @@ +/* + This file is part of Subsonic. + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see <http://www.gnu.org/licenses/>. + Copyright 2016 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.updates; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Build; + +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Util; + +public class UpdaterNoDLNA extends Updater { + public UpdaterNoDLNA() { + super(534); + TAG = this.getClass().getSimpleName(); + } + + @Override + public void update(Context context) { + SharedPreferences prefs = Util.getPreferences(context); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED, false); + editor.commit(); + } + } +} diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index d692f4d2..281c87d7 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -177,7 +177,8 @@ public final class Constants { public static final String PREFERENCES_KEY_HEADS_UP_NOTIFICATION = "headsUpNotification"; public static final String PREFERENCES_KEY_CAST_CACHE = "castCache"; public static final String PREFERENCES_KEY_PLAYBACK_SPEED = "playbackSpeed"; - public static final String PREFERENCES_KEY_SONG_PLAYBACK_SPEED = "songPlaybackSpeed"; + public static final String PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED = "customPlaybackSpeed"; + public static final String PREFERENCES_KEY_DLNA_CASTING_ENABLED = "dlnaCastingEnabled"; public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount"; public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; diff --git a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java index 9aa54c4b..73ec6aec 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java +++ b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java @@ -48,6 +48,7 @@ public class MediaRouteManager extends MediaRouter.Callback { private MediaRouteSelector selector; private List<MediaRouteProvider> providers = new ArrayList<MediaRouteProvider>(); private List<MediaRouteProvider> onlineProviders = new ArrayList<MediaRouteProvider>(); + private DLNARouteProvider dlnaProvider; static { try { @@ -159,10 +160,8 @@ public class MediaRouteManager extends MediaRouter.Callback { addOnlineProviders(); } - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - DLNARouteProvider dlnaProvider = new DLNARouteProvider(downloadService); - router.addProvider(dlnaProvider); - providers.add(dlnaProvider); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && Util.getPreferences(downloadService).getBoolean(Constants.PREFERENCES_KEY_DLNA_CASTING_ENABLED, true)) { + addDLNAProvider(); } } public void buildSelector() { @@ -178,4 +177,20 @@ public class MediaRouteManager extends MediaRouter.Callback { } selector = builder.build(); } + + public void addDLNAProvider() { + if(dlnaProvider == null) { + dlnaProvider = new DLNARouteProvider(downloadService); + router.addProvider(dlnaProvider); + providers.add(dlnaProvider); + } + } + public void removeDLNAProvider() { + if(dlnaProvider != null) { + router.removeProvider(dlnaProvider); + providers.remove(dlnaProvider); + dlnaProvider.destroy(); + dlnaProvider = null; + } + } } diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java index d666afb2..00bca833 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java +++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java @@ -433,7 +433,9 @@ public class RemoteControlClientLP extends RemoteControlClientBase { } private void noResults() { - + // Keep getting emails from Google that not playing something with no results is bad + downloadService.clear(); + downloadService.setShufflePlayEnabled(true); } private class EventCallback extends MediaSession.Callback { |