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
<uses-permission android:name="android.permission.INTERNET"/> |
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
<?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"> |
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
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); | |
TrackSelection.Factory videoTrackSelectionFactory = | |
new AdaptiveTrackSelection.Factory(bandwidthMeter); | |
TrackSelector trackSelector = | |
new DefaultTrackSelector(videoTrackSelectionFactory); | |
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); |
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
exoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); | |
exoPlayerView.setPlayer(player); |
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
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( |
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
@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); |
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
@Override | |
public void onPause() { | |
super.onPause(); | |
if (Util.SDK_INT <= 23) { | |
releasePlayer(); | |
} | |
} | |
@Override | |
public void onStop() { |
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
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) { |
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
override fun onBillingSetupFinished(billingResult: BillingResult) { | |
when (billingResult.responseCode) { | |
BillingClient.BillingResponseCode.OK -> { | |
Log.d(LOG_TAG, "onBillingSetupFinished successfully") | |
... | |
queryPurchases() | |
} | |
... | |
} |
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
fun queryPurchasesAsync() { | |
val purchasesResult = HashSet<Purchase>() | |
var result = playStoreBillingClient.queryPurchases(BillingClient.SkuType.INAPP) | |
if(nullOrEmpty(result)) { | |
queryPurchaseHistoryAsync() | |
} else { | |
result?.purchasesList?.let { purchasesResult.addAll(it) } | |
} | |
} |
OlderNewer