forked from PierfrancescoSoffritti/android-youtube-player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for playlist controls
- Loading branch information
1 parent
a92b95d
commit f2f9e71
Showing
10 changed files
with
262 additions
and
52 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
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
89 changes: 50 additions & 39 deletions
89
...i/androidyoutubeplayer/core/sampleapp/examples/playlistExample/PlaylistExampleActivity.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 |
---|---|---|
@@ -1,54 +1,65 @@ | ||
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.playlistExample; | ||
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.playlistExample | ||
|
||
import android.content.res.Configuration; | ||
import android.os.Bundle; | ||
import android.os.Bundle | ||
import android.widget.Button | ||
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.options.IFramePlayerOptions | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView | ||
import com.pierfrancescosoffritti.aytplayersample.R | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
class PlaylistExampleActivity : AppCompatActivity() { | ||
private var youTubePlayerView: YouTubePlayerView? = null | ||
private var youTubePlayer: YouTubePlayer? = null | ||
|
||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener; | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.options.IFramePlayerOptions; | ||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView; | ||
import com.pierfrancescosoffritti.aytplayersample.R; | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_playlist_example) | ||
|
||
public class PlaylistExampleActivity extends AppCompatActivity { | ||
youTubePlayerView = findViewById<YouTubePlayerView>(R.id.youtube_player_view).apply { | ||
val iFramePlayerOptions = IFramePlayerOptions.Builder() | ||
.controls(1) | ||
.listType("playlist") | ||
.list(PLAYLIST_ID) | ||
.build() | ||
|
||
private static final String PLAYLIST_ID = "PLEpEmEcrrKJUhZkyIAgQ17Oxyd3fx_y1j"; | ||
private YouTubePlayerView youTubePlayerView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_playlist_example); | ||
lifecycle.addObserver(this) | ||
this.initialize( | ||
youtubePlayerListener, | ||
handleNetworkEvents = true, | ||
iFramePlayerOptions | ||
) | ||
} | ||
|
||
youTubePlayerView = findViewById(R.id.youtube_player_view); | ||
getLifecycle().addObserver(youTubePlayerView); | ||
findViewById<Button>(R.id.next_video_button).setOnClickListener { | ||
youTubePlayer?.nextVideo() | ||
} | ||
|
||
initYouTubePlayerView(); | ||
} | ||
findViewById<Button>(R.id.previous_video_button).setOnClickListener { | ||
youTubePlayer?.previousVideo() | ||
} | ||
|
||
private void initYouTubePlayerView() { | ||
IFramePlayerOptions iFramePlayerOptions = new IFramePlayerOptions.Builder() | ||
.controls(1) | ||
.listType("playlist") | ||
.list(PLAYLIST_ID) | ||
.build(); | ||
findViewById<Button>(R.id.play_second_video_button).setOnClickListener { | ||
youTubePlayer?.playVideoAt(1) | ||
} | ||
|
||
getLifecycle().addObserver(youTubePlayerView); | ||
findViewById<Button>(R.id.shuffle_button).setOnClickListener { | ||
youTubePlayer?.setShuffle(true) | ||
} | ||
|
||
youTubePlayerView.initialize(new AbstractYouTubePlayerListener() { | ||
}, true, iFramePlayerOptions); | ||
findViewById<Button>(R.id.loop_button).setOnClickListener { | ||
youTubePlayer?.setLoop(true) | ||
} | ||
} | ||
|
||
@Override | ||
public void onConfigurationChanged(@NonNull Configuration newConfig) { | ||
super.onConfigurationChanged(newConfig); | ||
companion object { | ||
private const val PLAYLIST_ID = "PLEpEmEcrrKJUhZkyIAgQ17Oxyd3fx_y1j" | ||
} | ||
|
||
// Checks the orientation of the screen | ||
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { | ||
youTubePlayerView.matchParent(); | ||
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { | ||
youTubePlayerView.wrapContent(); | ||
private val youtubePlayerListener = object : AbstractYouTubePlayerListener() { | ||
override fun onReady(youTubePlayer: YouTubePlayer) { | ||
this@PlaylistExampleActivity.youTubePlayer = youTubePlayer | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.