resume to position if player was in background, keep screen on in player
This commit is contained in:
		| @ -103,7 +103,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS | ||||
|  | ||||
|     fun startPlayer(streamUrl: String) { | ||||
|         val intent = Intent(this, PlayerActivity::class.java).apply { | ||||
|             putExtra("streamUrl", streamUrl) | ||||
|             putExtra(getString(R.string.intent_stream_url), streamUrl) | ||||
|         } | ||||
|         startActivity(intent) | ||||
|     } | ||||
|  | ||||
| @ -36,7 +36,13 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         setContentView(R.layout.activity_player) | ||||
|         hideBars() // Initial hide the bars | ||||
|  | ||||
|         streamUrl = intent.getStringExtra("streamUrl").toString() | ||||
|         savedInstanceState?.let { | ||||
|             currentWindow = it.getInt(getString(R.string.state_resume_window)) | ||||
|             playbackPosition = it.getLong(getString(R.string.state_resume_position)) | ||||
|             playWhenReady = it.getBoolean(getString(R.string.state_is_playing)) | ||||
|         } | ||||
|  | ||||
|         streamUrl = intent.getStringExtra(getString(R.string.intent_stream_url)).toString() | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -72,6 +78,13 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onSaveInstanceState(outState: Bundle) { | ||||
|         outState.putInt(getString(R.string.state_resume_window), currentWindow) | ||||
|         outState.putLong(getString(R.string.state_resume_position), playbackPosition) | ||||
|         outState.putBoolean(getString(R.string.state_is_playing), playWhenReady) | ||||
|         super.onSaveInstanceState(outState) | ||||
|     } | ||||
|  | ||||
|     private fun initPlayer() { | ||||
|         if (streamUrl.isEmpty()) { | ||||
|             Log.e(javaClass.name, "No stream url was set.") | ||||
| @ -84,9 +97,11 @@ class PlayerActivity : AppCompatActivity() { | ||||
|         val mediaSource = HlsMediaSource.Factory(dataSourceFactory) | ||||
|             .createMediaSource(MediaItem.fromUri(Uri.parse(streamUrl))) | ||||
|  | ||||
|         player.playWhenReady = playWhenReady | ||||
|         player.setMediaSource(mediaSource) | ||||
|         player.seekTo(playbackPosition) | ||||
|         player.prepare() | ||||
|         player.play() | ||||
|  | ||||
|  | ||||
|         player.addListener(object : Player.EventListener { | ||||
|             override fun onPlaybackStateChanged(state: Int) { | ||||
| @ -127,8 +142,12 @@ class PlayerActivity : AppCompatActivity() { | ||||
|             } | ||||
|         } else { | ||||
|             @Suppress("deprecation") | ||||
|             window.decorView.systemUiVisibility = | ||||
|                 (View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) | ||||
|             window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE | ||||
|                     or View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||||
|                     or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||||
|                     or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||||
|                     or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | ||||
|                     or View.SYSTEM_UI_FLAG_FULLSCREEN) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:keepScreenOn="true" | ||||
|     android:background="#000000" | ||||
|     tools:context=".PlayerActivity"> | ||||
|  | ||||
|  | ||||
| @ -18,4 +18,10 @@ | ||||
|     <string name="encrypted_preference_file_key" translatable="false">org.mosad.teapod.encrypted_preferences</string> | ||||
|     <string name="save_key_user_login" translatable="false">org.mosad.teapod.user_login</string> | ||||
|     <string name="save_key_user_password" translatable="false">org.mosad.teapod.user_password</string> | ||||
|  | ||||
|     <!-- intents & states --> | ||||
|     <string name="intent_stream_url" translatable="false">intent_stream_url</string> | ||||
|     <string name="state_resume_window" translatable="false">state_resume_window</string> | ||||
|     <string name="state_resume_position" translatable="false">state_resume_position</string> | ||||
|     <string name="state_is_playing" translatable="false">state_is_playing</string> | ||||
| </resources> | ||||
		Reference in New Issue
	
	Block a user