-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/auto-fullscreen-on-orientation (#936)
* Add `YouTubePlayer#toggleFullscreen` This allows users to enter and exit fullscreen programmatically. In order for the function to be available the `origin` option should be set to `https://www.youtube.com`.
- Loading branch information
1 parent
3613ccd
commit 694c674
Showing
8 changed files
with
97 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
...oidyoutubeplayer/core/sampleapp/examples/fullscreenExample/FullscreenExampleActivity.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...droidyoutubeplayer/core/sampleapp/examples/fullscreenExample/FullscreenExampleActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.fullscreenExample | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.FrameLayout | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.FullScreenListener | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView | ||
import com.pierfrancescosoffritti.aytplayersample.R | ||
|
||
class FullscreenExampleActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_fullscreen_example) | ||
|
||
val youTubePlayerView = findViewById<YouTubePlayerView>(R.id.youtube_player_view) | ||
val fullScreenViewContainer = findViewById<FrameLayout>(R.id.full_screen_view_container) | ||
|
||
val iFramePlayerOptions = IFramePlayerOptions.Builder() | ||
.controls(1) // enable full screen button | ||
.fullscreen(1) | ||
.build() | ||
|
||
// we need to initialize manually in order to pass IFramePlayerOptions to the player | ||
youTubePlayerView.enableAutomaticInitialization = false | ||
|
||
youTubePlayerView.addFullScreenListener(object : FullScreenListener { | ||
override fun onEnterFullScreen(fullScreenView: View, exitFullScreen: Function0<Unit>) { | ||
// the video will continue playing in fullScreenView | ||
youTubePlayerView.visibility = View.GONE | ||
fullScreenViewContainer.visibility = View.VISIBLE | ||
fullScreenViewContainer.addView(fullScreenView) | ||
|
||
// optionally request landscape orientation | ||
// requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE | ||
} | ||
|
||
override fun onExitFullScreen() { | ||
// the video will continue playing in the player | ||
youTubePlayerView.visibility = View.VISIBLE | ||
fullScreenViewContainer.visibility = View.GONE | ||
fullScreenViewContainer.removeAllViews() | ||
} | ||
}) | ||
|
||
youTubePlayerView.initialize(object : AbstractYouTubePlayerListener() { | ||
override fun onReady(youTubePlayer: YouTubePlayer) { | ||
super.onReady(youTubePlayer) | ||
youTubePlayer.loadVideo("7NK_JOkuSVY", 0f) | ||
|
||
val enterFullscreenButton = findViewById<Button>(R.id.enter_fullscreen_button) | ||
enterFullscreenButton.setOnClickListener { | ||
youTubePlayer.toggleFullscreen() | ||
} | ||
} | ||
}, iFramePlayerOptions) | ||
|
||
lifecycle.addObserver(youTubePlayerView) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters