Search in sources :

Example 1 with PlayerView

use of androidx.media3.ui.PlayerView in project iGap-Android by KianIranian-STDG.

the class StoryDisplayFragment method createView.

@Override
public View createView(Context context) {
    fragmentView = new FrameLayout(context);
    rootLayout = (FrameLayout) fragmentView;
    notifyFrameLayout = new NotifyFrameLayout(context) {

        @Override
        public boolean dispatchKeyEventPreIme(KeyEvent event) {
            if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                if (keyboardViewVisible) {
                    hideStoryReply();
                    return true;
                }
                return false;
            }
            return super.dispatchKeyEventPreIme(event);
        }
    };
    notifyFrameLayout.setListener(this::onScreenSizeChanged);
    rootLayout.addView(notifyFrameLayout, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT));
    storyVideoPlayer = new PlayerView(context);
    storyVideoPlayer.setVisibility(View.GONE);
    storyVideoPlayer.setContentDescription("storyVideoPlayer");
    notifyFrameLayout.addView(storyVideoPlayer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT));
    storyDisplayImage = new ImageView(context);
    storyDisplayImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    storyDisplayImage.setContentDescription("storyDisplayImage");
    notifyFrameLayout.addView(storyDisplayImage, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT));
    DisplayMetrics displayMetrics = new DisplayMetrics();
    requireActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int width = displayMetrics.widthPixels;
    previous = new LinearLayout(context);
    FrameLayout.LayoutParams previousLayoutParam = new FrameLayout.LayoutParams(width / 2, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.LEFT);
    previous.setContentDescription("previous");
    notifyFrameLayout.addView(previous, previousLayoutParam);
    next = new LinearLayout(context);
    FrameLayout.LayoutParams nextLayoutParam = new FrameLayout.LayoutParams(width / 2, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.RIGHT);
    next.setContentDescription("next");
    notifyFrameLayout.addView(next, nextLayoutParam);
    storyVideoProgress = new ProgressBar(context);
    storyVideoProgress.setContentDescription("storyVideoProgress");
    notifyFrameLayout.addView(storyVideoProgress, LayoutCreator.createFrame(40, 40, Gravity.RIGHT | Gravity.TOP, 0, 20, 20, 0));
    storyOverlay = new FrameLayout(context);
    storyOverlay.setContentDescription("storyOverlay");
    notifyFrameLayout.addView(storyOverlay, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT));
    topShadow = new View(context);
    topShadow.setContentDescription("topShadow");
    topShadow.setBackground(context.getResources().getDrawable(R.drawable.story_top_shadow));
    storyOverlay.addView(topShadow, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 60, Gravity.TOP));
    storiesProgressView = new StoriesProgressView(context, null);
    storiesProgressView.setContentDescription("storiesProgressView");
    storiesProgressView.setPadding(8, 0, 8, 0);
    storyOverlay.addView(storiesProgressView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 0, 2, 0, 0));
    profileImage = new CircleImageView(context);
    profileImage.setContentDescription("profileImage");
    storyOverlay.addView(profileImage, LayoutCreator.createFrame(40, 40, Gravity.LEFT, 8, 10, 8, 8));
    LinearLayout profileContainer = new LinearLayout(context);
    profileContainer.setContentDescription("profileContainer");
    profileContainer.setOrientation(LinearLayout.VERTICAL);
    topLinearRootView = new LinearLayout(context);
    topLinearRootView.setGravity(Gravity.CENTER);
    topLinearRootView.setOrientation(LinearLayout.HORIZONTAL);
    profileContainer.addView(topLinearRootView, 0, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP));
    nickName = new TextView(context);
    nickName.setContentDescription("nickName");
    nickName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
    nickName.setTypeface(ResourcesCompat.getFont(context, R.font.main_font_bold));
    nickName.setTextColor(Color.WHITE);
    topLinearRootView.addView(nickName, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER));
    chatIconTv = new FontIconTextView(getContext());
    setTextSize(chatIconTv, R.dimen.dp14);
    chatIconTv.setVisibility(View.GONE);
    chatIconTv.setContentDescription("chatIconTv");
    chatIconTv.setText(R.string.icon_channel);
    chatIconTv.setTextColor(Color.WHITE);
    topLinearRootView.addView(chatIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, 4, 0, 0, 0));
    verifyIconTv = new FontIconTextView(getContext());
    verifyIconTv.setTextColor(getContext().getResources().getColor(R.color.verify_color));
    verifyIconTv.setText(R.string.icon_blue_badge);
    verifyIconTv.setVisibility(View.GONE);
    setTextSize(verifyIconTv, R.dimen.standardTextSize);
    topLinearRootView.addView(verifyIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, 4, 0, 0, 0));
    storyTime = new TextView(context);
    storyTime.setContentDescription("storyTime");
    storyTime.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    storyTime.setTypeface(nickName.getTypeface(), Typeface.BOLD);
    storyTime.setTextColor(Color.WHITE);
    profileContainer.addView(storyTime, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM));
    storyOverlay.addView(profileContainer, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.LEFT, 56, 8, 0, 0));
    captionRootView = new ExpandableTextView(context);
    captionRootView.setContentDescription("captionRootView");
    captionRootView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    captionRootView.setTextColor(Color.WHITE);
    captionRootView.setPadding(8, 8, 8, 8);
    rootLayout.addView(captionRootView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 0, 80));
    storySeenContainer = new LinearLayout(context);
    storySeenContainer.setContentDescription("storySeenContainer");
    storySeenContainer.setGravity(Gravity.CENTER_VERTICAL);
    storySeenContainer.setOrientation(LinearLayout.HORIZONTAL);
    eyeIcon = new TextView(context);
    eyeIcon.setContentDescription("eyeIcon");
    eyeIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    eyeIcon.setTextColor(Color.WHITE);
    eyeIcon.setGravity(Gravity.CENTER_VERTICAL);
    eyeIcon.setBackground(context.getResources().getDrawable(R.drawable.ic_view_seen));
    eyeIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
    seenCount = new TextView(context);
    seenCount.setContentDescription("seenCount");
    seenCount.setTypeface(ResourcesCompat.getFont(context, R.font.main_font));
    seenCount.setGravity(Gravity.CENTER_VERTICAL);
    seenCount.setTextColor(Color.WHITE);
    seenCount.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    storySeenContainer.addView(eyeIcon, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.LEFT));
    storySeenContainer.addView(seenCount, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.RIGHT, 3, 0, 0, 0));
    storyProgress = new ProgressBar(context);
    storyProgress.setContentDescription("storyProgress");
    storyProgress.setVisibility(View.GONE);
    notifyFrameLayout.addView(storyProgress, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER));
    GradientDrawable layer1 = new GradientDrawable();
    layer1.setShape(GradientDrawable.RECTANGLE);
    layer1.setCornerRadii(new float[] { LayoutCreator.dp(8), LayoutCreator.dp(8), 0, 0, 0, 0, LayoutCreator.dp(8), LayoutCreator.dp(8) });
    layer1.setColor(Theme.getInstance().getToolbarBackgroundColor(context));
    GradientDrawable layer2 = new GradientDrawable();
    layer2.setShape(GradientDrawable.RECTANGLE);
    layer2.setColor(Theme.getInstance().getReplyContentBackground(context));
    InsetDrawable insetDrawable = new InsetDrawable(layer2, LayoutCreator.dp(8), 0, 0, 0);
    LayerDrawable drawable = new LayerDrawable(new Drawable[] { layer1, insetDrawable });
    LinearLayout replyAndKeyboardContainer = new LinearLayout(context);
    replyAndKeyboardContainer.setOrientation(LinearLayout.VERTICAL);
    notifyFrameLayout.addView(replyAndKeyboardContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM));
    replyContainer = new FrameLayout(context);
    replyContainer.setVisibility(View.GONE);
    replyContainer.setContentDescription("replyContainer");
    replyContainer.setBackground(Theme.getInstance().tintDrawable(context.getResources().getDrawable(R.drawable.chat_item_sent_bg_light), context, R.attr.iGapSendMessageBubbleColor));
    replyContainer.setPadding(15, 15, 15, 15);
    replyAndKeyboardContainer.addView(replyContainer, LayoutCreator.createLinear(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 15, 0, 15, 10));
    FrameLayout mainContentContainer = new FrameLayout(context);
    replyContainer.addView(mainContentContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.LEFT));
    replyContentContainer = new LinearLayout(context);
    replyContentContainer.setContentDescription("replyContentContainer");
    replyContentContainer.setBackground(drawable);
    replyContentContainer.setOrientation(LinearLayout.VERTICAL);
    mainContentContainer.addView(replyContentContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, 50, Gravity.LEFT, 10, 5, 45, 5));
    replyThumb = new ImageView(context);
    replyThumb.setContentDescription("replyThumb");
    mainContentContainer.addView(replyThumb, LayoutCreator.createFrame(25, LayoutCreator.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 5, 0));
    replyTo = new TextView(context);
    replyTo.setContentDescription("replyTo");
    replyTo.setTypeface(ResourcesCompat.getFont(context, R.font.main_font_bold));
    replyTo.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    replyTo.setEllipsize(TextUtils.TruncateAt.END);
    replyTo.setTextColor(Theme.getInstance().getSendReplayUserColor(context));
    replyContentContainer.addView(replyTo, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 8, 0, 0, 0));
    replyCaption = new TextView(context);
    replyCaption.setContentDescription("replyCaption");
    replyCaption.setTypeface(ResourcesCompat.getFont(context, R.font.main_font));
    replyCaption.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    replyCaption.setEllipsize(TextUtils.TruncateAt.END);
    replyCaption.setSingleLine(true);
    replyCaption.setTextColor(Theme.getInstance().getSubTitleColor(context));
    replyContentContainer.addView(replyCaption, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM, 8, 0, 8, 0));
    sendReplyContainer = new FrameLayout(context);
    sendReplyContainer.setContentDescription("sendReplyContainer");
    replyContainer.addView(sendReplyContainer, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM, 0, 60, 0, 0));
    emojiIcon = new TextView(context);
    emojiIcon.setContentDescription("emojiIcon");
    emojiIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    emojiIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
    emojiIcon.setText(R.string.icon_emoji_smile);
    emojiIcon.setGravity(Gravity.CENTER);
    emojiIcon.setTextColor(Theme.getInstance().getSubTitleColor(context));
    sendReplyContainer.addView(emojiIcon, LayoutCreator.createFrame(50, 50, Gravity.LEFT, 5, 0, 5, 0));
    replyEditText = new EventEditText(context);
    replyEditText.setBackground(null);
    replyEditText.setContentDescription("replyEditText");
    replyEditText.setListener(this::chatMotionEvent);
    replyEditText.setHintTextColor(Theme.getInstance().getSubTitleColor(context));
    replyEditText.setTextColor(Theme.getInstance().getTitleTextColor(context));
    sendReplyContainer.addView(replyEditText, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT, Gravity.LEFT, 50, 0, 55, 0));
    sendIcon = new TextView(context);
    sendIcon.setContentDescription("sendIcon");
    sendIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    sendIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
    sendIcon.setText(R.string.icon_send);
    sendIcon.setGravity(Gravity.CENTER);
    sendIcon.setTextColor(Theme.getInstance().getSubTitleColor(context));
    sendReplyContainer.addView(sendIcon, LayoutCreator.createFrame(50, 50, Gravity.RIGHT, 5, 0, 5, 0));
    keyboardContainer = new FrameLayout(context);
    keyboardContainer.setContentDescription("keyboardContainer");
    replyAndKeyboardContainer.addView(keyboardContainer, LayoutCreator.createLinear(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM));
    storyReplyContainer = new LinearLayout(context);
    storyReplyContainer.setContentDescription("storyReplyContainer");
    storyReplyContainer.setOrientation(LinearLayout.VERTICAL);
    storyReplyContainer.setGravity(Gravity.CENTER_HORIZONTAL);
    replyIcon = new TextView(context);
    replyIcon.setContentDescription("replyIcon");
    replyIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    replyIcon.setTextColor(Color.WHITE);
    replyIcon.setText(R.string.icon_chevron_Down);
    replyIcon.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    replyText = new TextView(context);
    replyText.setContentDescription("replyText");
    replyText.setTypeface(ResourcesCompat.getFont(context, R.font.main_font));
    replyText.setTextColor(Color.WHITE);
    replyText.setText(R.string.replay);
    replyText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    storyReplyContainer.addView(replyIcon, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT));
    storyReplyContainer.addView(replyText, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT));
    notifyFrameLayout.addView(storySeenContainer, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 20));
    notifyFrameLayout.addView(storyReplyContainer, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 30));
    return rootLayout;
}
Also used : ExpandableTextView(net.iGap.story.ExpandableTextView) EventEditText(net.iGap.module.customView.EventEditText) FontIconTextView(net.iGap.module.FontIconTextView) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) FontIconTextView(net.iGap.module.FontIconTextView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) RecyclerListView(net.iGap.module.customView.RecyclerListView) View(android.view.View) KeyboardView(net.iGap.libs.emojiKeyboard.KeyboardView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ExpandableTextView(net.iGap.story.ExpandableTextView) EmojiView(net.iGap.libs.emojiKeyboard.EmojiView) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) CircleImageView(net.iGap.module.CircleImageView) GradientDrawable(android.graphics.drawable.GradientDrawable) KeyEvent(android.view.KeyEvent) CircleImageView(net.iGap.module.CircleImageView) FrameLayout(android.widget.FrameLayout) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout) LayerDrawable(android.graphics.drawable.LayerDrawable) PlayerView(com.google.android.exoplayer2.ui.PlayerView) FontIconTextView(net.iGap.module.FontIconTextView) TextView(android.widget.TextView) ExpandableTextView(net.iGap.story.ExpandableTextView) InsetDrawable(android.graphics.drawable.InsetDrawable) ImageView(android.widget.ImageView) CircleImageView(net.iGap.module.CircleImageView) ProgressBar(android.widget.ProgressBar) LinearLayout(android.widget.LinearLayout) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout)

Example 2 with PlayerView

use of androidx.media3.ui.PlayerView in project media by androidx.

the class PlayerActivity method createMediaSourceFactory.

private MediaSource.Factory createMediaSourceFactory() {
    ImaServerSideAdInsertionMediaSource.AdsLoader.Builder serverSideAdLoaderBuilder = new ImaServerSideAdInsertionMediaSource.AdsLoader.Builder(/* context= */
    this, playerView);
    if (serverSideAdsLoaderState != null) {
        serverSideAdLoaderBuilder.setAdsLoaderState(serverSideAdsLoaderState);
    }
    serverSideAdsLoader = serverSideAdLoaderBuilder.build();
    ImaServerSideAdInsertionMediaSource.Factory imaServerSideAdInsertionMediaSourceFactory = new ImaServerSideAdInsertionMediaSource.Factory(serverSideAdsLoader, new DefaultMediaSourceFactory(dataSourceFactory));
    return new DefaultMediaSourceFactory(dataSourceFactory).setAdsLoaderProvider(this::getClientSideAdsLoader).setAdViewProvider(playerView).setServerSideAdInsertionMediaSourceFactory(imaServerSideAdInsertionMediaSourceFactory);
}
Also used : DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) ImaServerSideAdInsertionMediaSource(androidx.media3.exoplayer.ima.ImaServerSideAdInsertionMediaSource) RenderersFactory(androidx.media3.exoplayer.RenderersFactory) DefaultMediaSourceFactory(androidx.media3.exoplayer.source.DefaultMediaSourceFactory) AdsLoader(androidx.media3.exoplayer.source.ads.AdsLoader) ImaAdsLoader(androidx.media3.exoplayer.ima.ImaAdsLoader)

Example 3 with PlayerView

use of androidx.media3.ui.PlayerView in project media by androidx.

the class TransformerActivity method startTransformation.

@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "progressIndicator", "transformationStopwatch", "progressViewGroup", "debugFrame" })
private void startTransformation() {
    requestTransformerPermission();
    Intent intent = getIntent();
    Uri uri = checkNotNull(intent.getData());
    try {
        externalCacheFile = createExternalCacheFile("transformer-output.mp4");
        String filePath = externalCacheFile.getAbsolutePath();
        @Nullable Bundle bundle = intent.getExtras();
        Transformer transformer = createTransformer(bundle, filePath);
        transformationStopwatch.start();
        transformer.startTransformation(MediaItem.fromUri(uri), filePath);
        this.transformer = transformer;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    informationTextView.setText(R.string.transformation_started);
    playerView.setVisibility(View.GONE);
    Handler mainHandler = new Handler(getMainLooper());
    ProgressHolder progressHolder = new ProgressHolder();
    mainHandler.post(new Runnable() {

        @Override
        public void run() {
            if (transformer != null && transformer.getProgress(progressHolder) != Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
                progressIndicator.setProgress(progressHolder.progress);
                informationTextView.setText(getString(R.string.transformation_timer, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
                mainHandler.postDelayed(/* r= */
                this, /* delayMillis= */
                500);
            }
        }
    });
}
Also used : Transformer(androidx.media3.transformer.Transformer) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable) ProgressHolder(androidx.media3.transformer.ProgressHolder) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 4 with PlayerView

use of androidx.media3.ui.PlayerView in project media by androidx.

the class TransformerActivity method playMediaItem.

@RequiresNonNull({ "playerView", "debugTextView" })
private void playMediaItem(MediaItem mediaItem) {
    playerView.setPlayer(null);
    releasePlayer();
    ExoPlayer player = new ExoPlayer.Builder(/* context= */
    this).build();
    playerView.setPlayer(player);
    player.setMediaItem(mediaItem);
    player.play();
    player.prepare();
    this.player = player;
    debugTextViewHelper = new DebugTextViewHelper(player, debugTextView);
    debugTextViewHelper.start();
}
Also used : DebugTextViewHelper(androidx.media3.exoplayer.util.DebugTextViewHelper) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 5 with PlayerView

use of androidx.media3.ui.PlayerView in project media by androidx.

the class MainActivity method initializePlayer.

private void initializePlayer() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri uri = ACTION_VIEW.equals(action) ? Assertions.checkNotNull(intent.getData()) : Uri.parse(DEFAULT_MEDIA_URI);
    DrmSessionManager drmSessionManager;
    if (Util.SDK_INT >= 18 && intent.hasExtra(DRM_SCHEME_EXTRA)) {
        String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
        String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
        UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
        HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSource.Factory();
        HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
        drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(drmSchemeUuid, FrameworkMediaDrm.DEFAULT_PROVIDER).build(drmCallback);
    } else {
        drmSessionManager = DrmSessionManager.DRM_UNSUPPORTED;
    }
    DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
    MediaSource mediaSource;
    @C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
    if (type == C.TYPE_DASH) {
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else if (type == C.TYPE_OTHER) {
        mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else {
        throw new IllegalStateException();
    }
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    VideoProcessingGLSurfaceView videoProcessingGLSurfaceView = Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
    videoProcessingGLSurfaceView.setPlayer(player);
    Assertions.checkNotNull(playerView).setPlayer(player);
    player.addAnalyticsListener(new EventLogger(/* trackSelector= */
    null));
    this.player = player;
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) GlUtil(androidx.media3.common.util.GlUtil) HttpDataSource(androidx.media3.datasource.HttpDataSource) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Toast(android.widget.Toast) Assertions(androidx.media3.common.util.Assertions) DefaultDataSource(androidx.media3.datasource.DefaultDataSource) MediaItem(androidx.media3.common.MediaItem) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) MediaSource(androidx.media3.exoplayer.source.MediaSource) Player(androidx.media3.common.Player) FrameworkMediaDrm(androidx.media3.exoplayer.drm.FrameworkMediaDrm) ProgressiveMediaSource(androidx.media3.exoplayer.source.ProgressiveMediaSource) UUID(java.util.UUID) Util(androidx.media3.common.util.Util) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) HttpMediaDrmCallback(androidx.media3.exoplayer.drm.HttpMediaDrmCallback) DataSource(androidx.media3.datasource.DataSource) EventLogger(androidx.media3.exoplayer.util.EventLogger) C(androidx.media3.common.C) Nullable(androidx.annotation.Nullable) PlayerView(androidx.media3.ui.PlayerView) Activity(android.app.Activity) EventLogger(androidx.media3.exoplayer.util.EventLogger) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) DefaultDrmSessionManager(androidx.media3.exoplayer.drm.DefaultDrmSessionManager) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(androidx.media3.exoplayer.ExoPlayer) Uri(android.net.Uri) HttpDataSource(androidx.media3.datasource.HttpDataSource) DefaultDataSource(androidx.media3.datasource.DefaultDataSource) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) DataSource(androidx.media3.datasource.DataSource) DashMediaSource(androidx.media3.exoplayer.dash.DashMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) ProgressiveMediaSource(androidx.media3.exoplayer.source.ProgressiveMediaSource) HttpDataSource(androidx.media3.datasource.HttpDataSource) DefaultHttpDataSource(androidx.media3.datasource.DefaultHttpDataSource) HttpMediaDrmCallback(androidx.media3.exoplayer.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Aggregations

PlayerView (com.google.android.exoplayer2.ui.PlayerView)7 Nullable (androidx.annotation.Nullable)5 FrameLayout (android.widget.FrameLayout)4 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MediaItem (androidx.media3.common.MediaItem)2 Player (androidx.media3.common.Player)2 ExoPlayer (androidx.media3.exoplayer.ExoPlayer)2 ParseException (java.text.ParseException)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Matrix (android.graphics.Matrix)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 InsetDrawable (android.graphics.drawable.InsetDrawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1