-
-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fullscreen option to IFramePlayerOptions (#926)
This change exposes the fs option in the IFramePlayerOptions. When set to 1 this option causes the full screen button to show up in the IFrame Player. This change also introduces a `FullScreenListener` that can be added to `YouTubePlayerView` in order to react to full screen event (when the user clicks the full screen button in the IFrame Player). --------- Co-authored-by: Pierfrancesco Soffritti <soffritti.pierfrancesco@gmail.com>
- Loading branch information
1 parent
c79f7ee
commit 70dc609
Showing
14 changed files
with
233 additions
and
11 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
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: 76 additions & 0 deletions
76
...oidyoutubeplayer/core/sampleapp/examples/fullscreenExample/FullscreenExampleActivity.java
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,76 @@ | ||
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.fullscreenExample; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
|
||
import androidx.annotation.NonNull; | ||
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; | ||
|
||
import kotlin.Unit; | ||
import kotlin.jvm.functions.Function0; | ||
|
||
public class FullscreenExampleActivity extends AppCompatActivity { | ||
|
||
private YouTubePlayerView youTubePlayerView; | ||
private FrameLayout fullScreenViewContainer; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fullscreen_example); | ||
|
||
youTubePlayerView = findViewById(R.id.youtube_player_view); | ||
fullScreenViewContainer = findViewById(R.id.full_screen_view_container); | ||
|
||
IFramePlayerOptions iFramePlayerOptions = new 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.setEnableAutomaticInitialization(false); | ||
|
||
youTubePlayerView.addFullScreenListener(new FullScreenListener() { | ||
@Override | ||
public void onEnterFullScreen(@NonNull View fullScreenView, @NonNull Function0<Unit> exitFullScreen) { | ||
// the video will continue playing in fullScreenView | ||
youTubePlayerView.setVisibility(View.GONE); | ||
fullScreenViewContainer.setVisibility(View.VISIBLE); | ||
fullScreenViewContainer.addView(fullScreenView); | ||
|
||
// optionally request landscape orientation | ||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
} | ||
|
||
@Override | ||
public void onExitFullScreen() { | ||
// the video will continue playing in the player | ||
youTubePlayerView.setVisibility(View.VISIBLE); | ||
fullScreenViewContainer.setVisibility(View.GONE); | ||
fullScreenViewContainer.removeAllViews(); | ||
|
||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | ||
} | ||
}); | ||
|
||
youTubePlayerView.initialize(new AbstractYouTubePlayerListener() { | ||
@Override | ||
public void onReady(@NonNull YouTubePlayer youTubePlayer) { | ||
super.onReady(youTubePlayer); | ||
youTubePlayer.loadVideo("S0Q4gqBUs7c", 0F); | ||
} | ||
}, iFramePlayerOptions); | ||
|
||
getLifecycle().addObserver(youTubePlayerView); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core-sample-app/src/main/res/layout/activity_fullscreen_example.xml
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" > | ||
|
||
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView | ||
android:id="@+id/youtube_player_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
|
||
<FrameLayout | ||
android:id="@+id/full_screen_view_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
2 changes: 2 additions & 0 deletions
2
...escosoffritti/androidyoutubeplayer/core/player/listeners/AbstractYouTubePlayerListener.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
31 changes: 31 additions & 0 deletions
31
...m/pierfrancescosoffritti/androidyoutubeplayer/core/player/listeners/FullScreenListener.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,31 @@ | ||
package com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners | ||
|
||
import android.view.View | ||
|
||
/** | ||
* Interface used to keep track of full screen events | ||
*/ | ||
interface FullScreenListener { | ||
/** | ||
* Notify the host application that the player has entered full screen mode | ||
* (the full screen button in the player UI has been clicked). | ||
* After this call, the video will no longer be rendered in the [YouTubePlayerView], | ||
* but will instead be rendered in [fullScreenView]. | ||
* The host application should add this View to a container that fills the screen | ||
* in order to actually display the video full screen. | ||
* | ||
* The application can explicitly exit fullscreen mode by invoking [exitFullScreen] | ||
* (for example when the user presses the back button). | ||
* However, the player will show its own UI to exist fullscreen. | ||
* Regardless of how the player exits fullscreen mode, [onEnterFullScreen] will be invoked, | ||
* signaling for the application to remove the custom View. | ||
*/ | ||
fun onEnterFullScreen(fullScreenView: View, exitFullScreen: () -> Unit) | ||
|
||
/** | ||
* Notify the host application that the player has exited full screen mode. | ||
* The host application must hide the custom View (the View which was previously passed to | ||
* [onEnterFullScreen]). After this call, the video will render in the player again. | ||
*/ | ||
fun onExitFullScreen() | ||
} |
2 changes: 2 additions & 0 deletions
2
...ierfrancescosoffritti/androidyoutubeplayer/core/player/listeners/YouTubePlayerListener.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
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
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