diff options
Diffstat (limited to 'subsonic-android/src')
9 files changed, 41 insertions, 15 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 165054d2..0bcaa28a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -377,8 +377,10 @@ public class SearchActivity extends SubsonicTabActivity { } private void onVideoSelected(MusicDirectory.Entry entry) { + int maxBitrate = Util.getMaxVideoBitrate(this); + Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId()))); + intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(maxBitrate, this, entry.getId()))); startActivity(intent); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 6362f039..9ddaecf3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -553,8 +553,10 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } private void playWebView(MusicDirectory.Entry entry) { + int maxBitrate = Util.getMaxVideoBitrate(this); + Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(this, entry.getId()))); + intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(maxBitrate, this, entry.getId()))); startActivity(intent); } @@ -575,8 +577,10 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } } private void streamExternalPlayer(MusicDirectory.Entry entry) { + int maxBitrate = Util.getMaxVideoBitrate(this); + Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoStreamUrl(this, entry.getId())), "video/*"); + intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoStreamUrl(maxBitrate, this, entry.getId())), "video/*"); List<ResolveInfo> intents = getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java index 97c4c44d..fa57fc53 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java @@ -52,6 +52,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer private ListPreference theme; private ListPreference maxBitrateWifi; private ListPreference maxBitrateMobile; + private ListPreference maxVideoBitrateWifi; + private ListPreference maxVideoBitrateMobile; private ListPreference networkTimeout; private EditTextPreference cacheSize; private EditTextPreference cacheLocation; @@ -67,6 +69,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME); maxBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI); maxBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE); + maxVideoBitrateWifi = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI); + maxVideoBitrateMobile = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE); networkTimeout = (ListPreference) findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT); cacheSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE); cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION); @@ -155,6 +159,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer theme.setSummary(theme.getEntry()); maxBitrateWifi.setSummary(maxBitrateWifi.getEntry()); maxBitrateMobile.setSummary(maxBitrateMobile.getEntry()); + maxVideoBitrateWifi.setSummary(maxVideoBitrateWifi.getEntry()); + maxVideoBitrateMobile.setSummary(maxVideoBitrateMobile.getEntry()); networkTimeout.setSummary(networkTimeout.getEntry()); cacheSize.setSummary(cacheSize.getText()); cacheLocation.setSummary(cacheLocation.getText()); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index fe0a3f19..4028b029 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -216,13 +216,13 @@ public class CachedMusicService implements MusicService { } @Override - public String getVideoUrl(Context context, String id) { - return musicService.getVideoUrl(context, id); + public String getVideoUrl(int maxBitrate, Context context, String id) { + return musicService.getVideoUrl(maxBitrate, context, id); } @Override - public String getVideoStreamUrl(Context context, String id) { - return musicService.getVideoStreamUrl(context, id); + public String getVideoStreamUrl(int maxBitrate, Context context, String id) { + return musicService.getVideoStreamUrl(maxBitrate, context, id); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index 98951853..702b4aa7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -85,9 +85,9 @@ public interface MusicService { Version getLatestVersion(Context context, ProgressListener progressListener) throws Exception; - String getVideoUrl(Context context, String id); + String getVideoUrl(int maxBitrate, Context context, String id); - String getVideoStreamUrl(Context context, String id); + String getVideoStreamUrl(int Bitrate, Context context, String id); JukeboxStatus updateJukeboxPlaylist(List<String> ids, Context context, ProgressListener progressListener) throws Exception; diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 33b406cb..21bce39c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -335,12 +335,12 @@ public class OfflineMusicService extends RESTMusicService { } @Override - public String getVideoUrl(Context context, String id) { + public String getVideoUrl(int maxBitrate, Context context, String id) { return null; } @Override - public String getVideoStreamUrl(Context context, String id) { + public String getVideoStreamUrl(int maxBitrate, Context context, String id) { return null; } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 47f92bde..6a33e60d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -637,10 +637,10 @@ public class RESTMusicService implements MusicService { } @Override - public String getVideoUrl(Context context, String id) { + public String getVideoUrl(int maxBitrate, Context context, String id) { StringBuilder builder = new StringBuilder(Util.getRestUrl(context, "videoPlayer")); builder.append("&id=").append(id); - builder.append("&maxBitRate=500"); + builder.append("&maxBitRate=").append(maxBitrate); builder.append("&autoplay=true"); String url = rewriteUrlWithRedirect(context, builder.toString()); @@ -649,10 +649,10 @@ public class RESTMusicService implements MusicService { } @Override - public String getVideoStreamUrl(Context context, String id) { + public String getVideoStreamUrl(int maxBitrate, Context context, String id) { StringBuilder builder = new StringBuilder(Util.getRestUrl(context, "stream")); builder.append("&id=").append(id); - builder.append("&maxBitRate=500"); + builder.append("&maxBitRate=").append(maxBitrate); String url = rewriteUrlWithRedirect(context, builder.toString()); Log.i(TAG, "Using video URL: " + url); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index 4d48b6d4..bf344fe6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -65,6 +65,8 @@ public final class Constants { public static final String PREFERENCES_KEY_THEME = "theme"; public static final String PREFERENCES_KEY_MAX_BITRATE_WIFI = "maxBitrateWifi"; public static final String PREFERENCES_KEY_MAX_BITRATE_MOBILE = "maxBitrateMobile"; + public static final String PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI = "maxVideoBitrateWifi"; + public static final String PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE = "maxVideoBitrateMobile"; public static final String PREFERENCES_KEY_NETWORK_TIMEOUT = "networkTimeout"; public static final String PREFERENCES_KEY_CACHE_SIZE = "cacheSize"; public static final String PREFERENCES_KEY_CACHE_LOCATION = "cacheLocation"; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 09aa570c..bd10f1b7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -209,6 +209,18 @@ public final class Util { SharedPreferences prefs = getPreferences(context); return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE, "0")); } + + public static int getMaxVideoBitrate(Context context) { + ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = manager.getActiveNetworkInfo(); + if (networkInfo == null) { + return 0; + } + + boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI; + SharedPreferences prefs = getPreferences(context); + return Integer.parseInt(prefs.getString(wifi ? Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_VIDEO_BITRATE_MOBILE, "0")); + } public static int getPreloadCount(Context context) { SharedPreferences prefs = getPreferences(context); |