Launch video player in single task mode (fixes #154)

This commit is contained in:
Felix Ableitner 2016-09-28 13:09:42 +09:00
parent f9ac199c1f
commit 5f7ee15d1e
3 changed files with 53 additions and 35 deletions

View File

@ -29,6 +29,7 @@
<activity <activity
android:name=".detail.VideoItemDetailActivity" android:name=".detail.VideoItemDetailActivity"
android:label="@string/title_videoitem_detail" android:label="@string/title_videoitem_detail"
android:launchMode="singleTask"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"

View File

@ -111,6 +111,9 @@ class ActionBarHandler {
private int getDefaultResolution(final List<VideoStream> videoStreams) { private int getDefaultResolution(final List<VideoStream> videoStreams) {
if (defaultPreferences == null)
return 0;
String defaultResolution = defaultPreferences String defaultResolution = defaultPreferences
.getString(activity.getString(R.string.default_resolution_key), .getString(activity.getString(R.string.default_resolution_key),
activity.getString(R.string.default_resolution_value)); activity.getString(R.string.default_resolution_value));

View File

@ -68,52 +68,66 @@ public class VideoItemDetailActivity extends AppCompatActivity {
// http://developer.android.com/guide/components/fragments.html // http://developer.android.com/guide/components/fragments.html
// //
Bundle arguments = new Bundle();
if (savedInstanceState == null) { if (savedInstanceState == null) {
// this means the video was called though another app handleIntent(getIntent());
if (getIntent().getData() != null) {
videoUrl = getIntent().getData().toString();
StreamingService[] serviceList = ServiceList.getServices();
//StreamExtractor videoExtractor = null;
for (int i = 0; i < serviceList.length; i++) {
if (serviceList[i].getUrlIdHandlerInstance().acceptUrl(videoUrl)) {
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
currentStreamingService = i;
//videoExtractor = ServiceList.getService(i).getExtractorInstance();
break;
}
}
if(currentStreamingService == -1) {
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG)
.show();
}
//arguments.putString(VideoItemDetailFragment.VIDEO_URL,
// videoExtractor.getUrl(videoExtractor.getId(videoUrl)));//cleans URL
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.autoplay_through_intent_key), false));
} else {
videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL);
currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1);
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService);
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
}
} else { } else {
videoUrl = savedInstanceState.getString(VideoItemDetailFragment.VIDEO_URL); videoUrl = savedInstanceState.getString(VideoItemDetailFragment.VIDEO_URL);
currentStreamingService = savedInstanceState.getInt(VideoItemDetailFragment.STREAMING_SERVICE); currentStreamingService = savedInstanceState.getInt(VideoItemDetailFragment.STREAMING_SERVICE);
arguments = savedInstanceState; addFragment(savedInstanceState);
} }
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
Bundle arguments = new Bundle();
// this means the video was called though another app
if (intent.getData() != null) {
videoUrl = intent.getData().toString();
StreamingService[] serviceList = ServiceList.getServices();
//StreamExtractor videoExtractor = null;
for (int i = 0; i < serviceList.length; i++) {
if (serviceList[i].getUrlIdHandlerInstance().acceptUrl(videoUrl)) {
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i);
currentStreamingService = i;
//videoExtractor = ServiceList.getService(i).getExtractorInstance();
break;
}
}
if(currentStreamingService == -1) {
Toast.makeText(this, R.string.url_not_supported_toast, Toast.LENGTH_LONG)
.show();
}
//arguments.putString(VideoItemDetailFragment.VIDEO_URL,
// videoExtractor.getUrl(videoExtractor.getId(videoUrl)));//cleans URL
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY,
PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.autoplay_through_intent_key), false));
} else {
videoUrl = intent.getStringExtra(VideoItemDetailFragment.VIDEO_URL);
currentStreamingService = intent.getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1);
arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl);
arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService);
arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false);
}
addFragment(arguments);
}
private void addFragment(final Bundle arguments) {
// Create the detail fragment and add it to the activity // Create the detail fragment and add it to the activity
// using a fragment transaction. // using a fragment transaction.
fragment = new VideoItemDetailFragment(); fragment = new VideoItemDetailFragment();
fragment.setArguments(arguments); fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.add(R.id.videoitem_detail_container, fragment) .replace(R.id.videoitem_detail_container, fragment)
.commit(); .commit();
} }