Search in sources :

Example 36 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project odysee-android by OdyseeTeam.

the class FileViewFragment method setPlayerForPlayerView.

private void setPlayerForPlayerView() {
    View root = getView();
    if (root != null) {
        PlayerView view = root.findViewById(R.id.file_view_exoplayer_view);
        view.setVisibility(View.VISIBLE);
        view.setPlayer(null);
        view.setPlayer(MainActivity.appPlayer);
    }
}
Also used : PlayerView(com.google.android.exoplayer2.ui.PlayerView) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView)

Example 37 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project androidtv-news by anenasa.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    preferences = getSharedPreferences("io.github.anenasa.news", MODE_PRIVATE);
    channelNum = preferences.getInt("channelNum", 0);
    defaultFormat = preferences.getString("defaultFormat", "best");
    defaultVolume = preferences.getString("defaultVolume", "1.0");
    try {
        YoutubeDL.getInstance().init(getApplication());
    } catch (YoutubeDLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
        errorMessageView.setText(e.toString());
    }
    player = new SimpleExoPlayer.Builder(this).build();
    player.addListener(new Player.Listener() {

        @Override
        public void onPlayerError(@NonNull PlaybackException error) {
            Log.e(TAG, Log.getStackTraceString(error));
            errorMessageView.setText(error.toString());
            if (channel.get(channelNum).needParse() != Channel.NEEDPARSE_NO) {
                // Force parse by removing video url
                channel.get(channelNum).setVideo("");
            }
            play(channelNum);
        }

        @Override
        public void onPlaybackStateChanged(int state) {
            if (state == Player.STATE_READY) {
                errorMessageView.setText("");
            }
        }
    });
    playerView = findViewById(R.id.playerView);
    player.setVideoSurfaceView(playerView);
    textView = findViewById(R.id.textView);
    errorMessageView = findViewById(R.id.errorMessage);
    readChannelList();
    if (channel == null) {
        return;
    }
    if (channelNum >= channel.size()) {
        resetChannelNum();
    }
    timer = new Timer();
    timerTask = new TimerTask() {

        @Override
        public void run() {
            for (int i = 0; i < channel.size(); i++) {
                if (!channel.get(i).isHidden()) {
                    try {
                        channel.get(i).parse();
                    } catch (IOException | YoutubeDLException | JSONException | InterruptedException e) {
                        Log.e(TAG, Log.getStackTraceString(e));
                    }
                }
            }
            saveSettings();
        }
    };
    // Delay timer for one second because if two requests are sent to
    // Hami Video at the same time, one of them will fail.
    timer.scheduleAtFixedRate(timerTask, 1000, 3600000);
}
Also used : PlaybackException(com.google.android.exoplayer2.PlaybackException) Player(com.google.android.exoplayer2.Player) SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) YoutubeDLException(com.yausername.youtubedl_android.YoutubeDLException) Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 38 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project bolan by qiusunshine.

the class PlayerView method setPlayer.

/**
 * Set the {@link Player} to use.
 *
 * <p>To transition a {@link Player} from targeting one view to another, it's recommended to use
 * {@link #switchTargetView(Player, PlayerView, PlayerView)} rather than this method. If you do
 * wish to use this method directly, be sure to attach the player to the new view <em>before</em>
 * calling {@code setPlayer(null)} to detach it from the old one. This ordering is significantly
 * more efficient and may allow for more seamless transitions.
 *
 * @param player The {@link Player} to use, or {@code null} to detach the current player. Only
 *     players which are accessed on the main thread are supported ({@code
 *     player.getApplicationLooper() == Looper.getMainLooper()}).
 */
public void setPlayer(@Nullable Player player) {
    Assertions.checkState(Looper.myLooper() == Looper.getMainLooper());
    Assertions.checkArgument(player == null || player.getApplicationLooper() == Looper.getMainLooper());
    if (this.player == player) {
        return;
    }
    @Nullable Player oldPlayer = this.player;
    if (oldPlayer != null) {
        oldPlayer.removeListener(componentListener);
        if (oldPlayer.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
            if (surfaceView instanceof TextureView) {
                oldPlayer.clearVideoTextureView((TextureView) surfaceView);
            } else if (surfaceView instanceof SurfaceView) {
                oldPlayer.clearVideoSurfaceView((SurfaceView) surfaceView);
            }
        }
    }
    if (subtitleView != null) {
        subtitleView.setCues(null);
    }
    this.player = player;
    if (useController()) {
        controller.setPlayer(player);
    }
    updateBuffering();
    updateErrorMessage();
    updateForCurrentTrackSelections(/* isNewPlayer= */
    true);
    if (player != null) {
        if (player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
            if (surfaceView instanceof TextureView) {
                player.setVideoTextureView((TextureView) surfaceView);
            } else if (surfaceView instanceof SurfaceView) {
                player.setVideoSurfaceView((SurfaceView) surfaceView);
            }
            updateAspectRatio();
        }
        if (subtitleView != null && player.isCommandAvailable(COMMAND_GET_TEXT)) {
            subtitleView.setCues(player.getCurrentCues());
        }
        player.addListener(componentListener);
        maybeShowController(false);
        updateForCurrentTrackSelections(false);
    } else {
        hideController();
    }
}
Also used : Player(com.google.android.exoplayer2.Player) SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) ForwardingPlayer(com.google.android.exoplayer2.ForwardingPlayer) TextureView(android.view.TextureView) Nullable(androidx.annotation.Nullable) SurfaceView(android.view.SurfaceView) GLSurfaceView(android.opengl.GLSurfaceView)

Example 39 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project bolan by qiusunshine.

the class BaseView method initDanmuku.

private void initDanmuku(int lineCount) {
    if (danmakuView != null) {
        return;
    }
    // 设置最大显示行数
    HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
    // 滚动弹幕最大显示5行
    maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, lineCount);
    // 设置是否禁止重叠
    HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
    overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
    overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    danmakuView = new DanmakuView(getContext());
    // danmakuView.showFPS(true);
    getDanmuViewContainer().addView((DanmakuView) danmakuView, params);
    DanamakuAdapter danamakuAdapter = new DanamakuAdapter(danmakuView);
    danmakuContext = DanmakuContext.create();
    danmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3).setScrollSpeedFactor(1.2f).setCacheStuffer(new SpannedCacheStuffer(), // 图文混排使用SpannedCacheStuffer
    danamakuAdapter).setMaximumLines(maxLinesPair).preventOverlapping(overlappingEnablePair);
    addSeekListener();
    danmuDestroyed = false;
    if (danmakuView != null) {
        danmakuView.setCallback(new master.flame.danmaku.controller.DrawHandler.Callback() {

            @Override
            public void updateTimer(DanmakuTimer timer) {
                if (playerView != null && VideoPlayerManager.PLAY_SPEED > 1f || VideoPlayerManager.tempFastPlay) {
                    float speed = VideoPlayerManager.tempFastPlay ? VideoPlayerManager.PLAY_SPEED * 2 : VideoPlayerManager.PLAY_SPEED;
                    if (speed > 1f) {
                        timer.add((long) (timer.lastInterval() * (speed - 1)));
                    }
                }
            }

            @Override
            public void drawingFinished() {
            }

            @Override
            public void danmakuShown(BaseDanmaku danmaku) {
            }

            @Override
            public void prepared() {
                if (danmakuView != null) {
                    post(() -> {
                        if (playerView.getPlayer() != null && playerView.getPlayer().getCurrentPosition() > 0) {
                            Log.d(TAG, "xxxxxx-prepared: ");
                            if (danmakuView != null) {
                                danmakuView.start(getPlayerView().getPlayer().getCurrentPosition());
                            }
                        } else {
                            danmakuView.start();
                        }
                        if (!playerView.getPlayer().isPlaying()) {
                            danmakuView.pause();
                        }
                        resolveDanmakuShow();
                    });
                }
            }
        });
        danmakuView.enableDanmakuDrawingCache(true);
        if (getPlayerView().getPlayer() != null) {
            getPlayerView().getPlayer().addListener(new Player.Listener() {

                @Override
                public void onIsPlayingChanged(boolean isPlaying) {
                    if (danmaKuShow && danmakuView != null) {
                        if (isPlaying) {
                            danmakuView.resume();
                        } else {
                            danmakuView.pause();
                        }
                    }
                }
            });
        }
    }
}
Also used : Player(com.google.android.exoplayer2.Player) ExoUserPlayer(chuangyuan.ycj.videolibrary.video.ExoUserPlayer) HashMap(java.util.HashMap) DanamakuAdapter(chuangyuan.ycj.videolibrary.danmuku.DanamakuAdapter) DanmakuView(master.flame.danmaku.ui.widget.DanmakuView) IDanmakuView(master.flame.danmaku.controller.IDanmakuView) BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) SpannedCacheStuffer(master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer)

Example 40 with PlayerView

use of com.google.android.exoplayer2.ui.PlayerView in project android-p2p-engine by cdnbye.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // bugly
    // CrashReport.initCrashReport(getApplicationContext(), "e40b652a35", true);
    setContentView(R.layout.activity_main);
    offloadV = findViewById(R.id.offload);
    uploadV = findViewById(R.id.upload);
    peersV = findViewById(R.id.peers);
    connectedV = findViewById(R.id.connected);
    peerIdV = findViewById(R.id.peerId);
    ratioV = findViewById(R.id.ratio);
    playerView = findViewById(R.id.player_view);
    TextView versionV = findViewById(R.id.version);
    versionV.setText("Version: " + P2pEngine.Version);
    P2pConfig config = new P2pConfig.Builder().logEnabled(true).logLevel(LogLevel.DEBUG).p2pEnabled(true).withTag("exoplayer").channelIdPrefix("cdnbye").build();
    // Instantiate P2pEngine,which is a singleton
    P2pEngine engine = P2pEngine.initEngine(getApplicationContext(), "ZMuO5qHZg", config);
    // Recommended while playing living stream
    engine.setPlayStats(new PlayerStatsCallback() {

        @Override
        public long onBufferedDuration() {
            return player.getBufferedPosition() - player.getCurrentPosition();
        }
    });
    engine.addP2pStatisticsListener(new P2pStatisticsListener() {

        @Override
        public void onHttpDownloaded(long value) {
            totalHttpDownloaded += (double) value;
            refreshRatio();
        }

        @Override
        public void onP2pDownloaded(long value) {
            totalP2pDownloaded += (double) value;
            String text = String.format("Offload: %.2fMB", totalP2pDownloaded / 1024);
            offloadV.setText(text);
            refreshRatio();
        }

        @Override
        public void onP2pUploaded(long value) {
            totalP2pUploaded += (double) value;
            String text = String.format("Upload: %.2fMB", totalP2pUploaded / 1024);
            uploadV.setText(text);
        }

        @Override
        public void onPeers(List<String> peers) {
            String text = String.format("Peers: %d", peers.size());
            peersV.setText(text);
        }

        @Override
        public void onServerConnected(boolean connected) {
            String text = String.format("Connected: %s", connected ? "Yes" : "No");
            connectedV.setText(text);
            String text2 = String.format("Peer ID: %s", P2pEngine.getInstance().getPeerId());
            peerIdV.setText(text2);
        }
    });
    startPlay(currentUrl);
    replayBtn = findViewById(R.id.replay);
    switchBtn = findViewById(R.id.switcher);
    vodBtn = findViewById(R.id.vod);
    liveBtn = findViewById(R.id.live);
    replayBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // 清空数据
            clearData();
            if (player != null && player.isPlaying()) {
                player.stop();
            }
            startPlay(currentUrl);
        }
    });
    switchBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (currentUrl.equals(VOD)) {
                currentUrl = LIVE;
            } else {
                currentUrl = VOD;
            }
            // 清空数据
            clearData();
            startPlay(currentUrl);
        }
    });
    vodBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // 清空数据
            clearData();
            currentUrl = VOD;
            startPlay(currentUrl);
        }
    });
    liveBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // 清空数据
            clearData();
            currentUrl = LIVE;
            startPlay(currentUrl);
        }
    });
}
Also used : P2pStatisticsListener(com.cdnbye.sdk.P2pStatisticsListener) P2pEngine(com.cdnbye.sdk.P2pEngine) PlayerStatsCallback(com.cdnbye.sdk.PlayerStatsCallback) P2pConfig(com.cdnbye.sdk.P2pConfig) PlayerView(com.google.android.exoplayer2.ui.PlayerView) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView)

Aggregations

PlayerView (com.google.android.exoplayer2.ui.PlayerView)25 TextView (android.widget.TextView)20 View (android.view.View)15 ImageView (android.widget.ImageView)14 RecyclerView (androidx.recyclerview.widget.RecyclerView)13 WebView (android.webkit.WebView)12 Uri (android.net.Uri)10 AdapterView (android.widget.AdapterView)10 NestedScrollView (androidx.core.widget.NestedScrollView)10 PhotoView (com.github.chrisbanes.photoview.PhotoView)10 SolidIconView (com.odysee.app.ui.controls.SolidIconView)10 MediaItem (com.google.android.exoplayer2.MediaItem)8 Context (android.content.Context)7 Nullable (androidx.annotation.Nullable)7 Player (com.google.android.exoplayer2.Player)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)7 ProgressiveMediaSource (com.google.android.exoplayer2.source.ProgressiveMediaSource)7 SuppressLint (android.annotation.SuppressLint)6 Intent (android.content.Intent)6 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)6