Skip to content

Instantly share code, notes, and snippets.

View isaidamier's full-sized avatar

Isai Damier isaidamier

View GitHub Profile
<uses-permission android:name="android.permission.INTERNET"/>
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
exoPlayerView.setPlayer(player);
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putLong(POS_KEY, player.getCurrentPosition());
super.onSaveInstanceState(outState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
long position = savedInstanceState.getLong(POS_KEY);
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
@Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
releasePlayer();
}
}
@Override
public void onStop() {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
this,
Util.getUserAgent(this, APP_NAME),
(DefaultBandwidthMeter) bandwidthMeter);//note the type casting
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
//normally we would have this in string.xml or such instead of hardcoding
String waterUrl="https://storage.googleapis.com/android-tv/Sample%20videos/" +
"Google%2B/Google%2B_%20Instant%20Upload.mp4"
MediaSource videoSource = new ExtractorMediaSource(
private fun instantiateAndConnectToPlayBillingService() {
playStoreBillingClient = BillingClient.newBuilder(application.applicationContext)
.enablePendingPurchases() // required or app will crash
.setListener(this).build()
connectToPlayBillingService()
}
private fun connectToPlayBillingService(): Boolean {
Log.d(LOG_TAG, "connectToPlayBillingService")
if (!playStoreBillingClient.isReady) {
override fun onBillingSetupFinished(billingResult: BillingResult) {
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK -> {
Log.d(LOG_TAG, "onBillingSetupFinished successfully")
...
queryPurchases()
}
...
}
fun queryPurchasesAsync() {
val purchasesResult = HashSet<Purchase>()
var result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.INAPP)
if(nullOrEmpty(result)) {
queryPurchaseHistoryAsync()
} else {
result?.purchasesList?.let { purchasesResult.addAll(it) }
}
}