mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 23:32:59 +00:00 
			
		
		
		
	Launch video player in single task mode (fixes #154)
This commit is contained in:
		| @@ -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" | ||||||
|   | |||||||
| @@ -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)); | ||||||
|   | |||||||
| @@ -68,11 +68,27 @@ 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) { | ||||||
|  |             handleIntent(getIntent()); | ||||||
|  |         } else { | ||||||
|  |             videoUrl = savedInstanceState.getString(VideoItemDetailFragment.VIDEO_URL); | ||||||
|  |             currentStreamingService = savedInstanceState.getInt(VideoItemDetailFragment.STREAMING_SERVICE); | ||||||
|  |             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 |         // this means the video was called though another app | ||||||
|             if (getIntent().getData() != null) { |         if (intent.getData() != null) { | ||||||
|                 videoUrl = getIntent().getData().toString(); |             videoUrl = intent.getData().toString(); | ||||||
|             StreamingService[] serviceList = ServiceList.getServices(); |             StreamingService[] serviceList = ServiceList.getServices(); | ||||||
|             //StreamExtractor videoExtractor = null; |             //StreamExtractor videoExtractor = null; | ||||||
|             for (int i = 0; i < serviceList.length; i++) { |             for (int i = 0; i < serviceList.length; i++) { | ||||||
| @@ -95,25 +111,23 @@ public class VideoItemDetailActivity extends AppCompatActivity { | |||||||
|                     PreferenceManager.getDefaultSharedPreferences(this) |                     PreferenceManager.getDefaultSharedPreferences(this) | ||||||
|                             .getBoolean(getString(R.string.autoplay_through_intent_key), false)); |                             .getBoolean(getString(R.string.autoplay_through_intent_key), false)); | ||||||
|         } else { |         } else { | ||||||
|                 videoUrl = getIntent().getStringExtra(VideoItemDetailFragment.VIDEO_URL); |             videoUrl = intent.getStringExtra(VideoItemDetailFragment.VIDEO_URL); | ||||||
|                 currentStreamingService = getIntent().getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1); |             currentStreamingService = intent.getIntExtra(VideoItemDetailFragment.STREAMING_SERVICE, -1); | ||||||
|             arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); |             arguments.putString(VideoItemDetailFragment.VIDEO_URL, videoUrl); | ||||||
|             arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService); |             arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingService); | ||||||
|             arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false); |             arguments.putBoolean(VideoItemDetailFragment.AUTO_PLAY, false); | ||||||
|         } |         } | ||||||
|  |         addFragment(arguments); | ||||||
|  |  | ||||||
|         } else { |  | ||||||
|             videoUrl = savedInstanceState.getString(VideoItemDetailFragment.VIDEO_URL); |  | ||||||
|             currentStreamingService = savedInstanceState.getInt(VideoItemDetailFragment.STREAMING_SERVICE); |  | ||||||
|             arguments = savedInstanceState; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     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(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Felix Ableitner
					Felix Ableitner