Search in sources :

Example 31 with Video

use of com.zype.android.Db.Entity.Video in project zype-android by zype.

the class VideoDetailActivity method initModel.

// //////////
// Data
// 
private void initModel() {
    final Video video = DataRepository.getInstance(getApplication()).getVideoSync(mVideoId);
    if (video != null) {
        // Load player urls
        playerViewModel = ViewModelProviders.of(this).get(PlayerViewModel.class);
        PlayerViewModel.PlayerMode mediaType = null;
        switch(mType) {
            case PlayerFragment.TYPE_AUDIO_LOCAL:
            case PlayerFragment.TYPE_AUDIO_WEB:
                mediaType = PlayerViewModel.PlayerMode.AUDIO;
                break;
            case PlayerFragment.TYPE_VIDEO_LOCAL:
            case PlayerFragment.TYPE_VIDEO_WEB:
            case BaseVideoActivity.TYPE_WEB:
                mediaType = PlayerViewModel.PlayerMode.VIDEO;
                break;
        }
        playerViewModel.init(video.id, playlistId, mediaType);
        playerViewModel.getPlayerError().observe(this, playerErrorObserver);
        playerViewModel.getPlayerUrl().observe(this, playerUrlObserver);
        if (video.isZypeLive == 0) {
            updateDownloadUrls();
        } else {
            // showVideoThumbnail();
            videoDetailViewModel = new VideoDetailViewModel(getApplication());
            final Observer<Video> videoObserver = new Observer<Video>() {

                @Override
                public void onChanged(@Nullable Video video) {
                    if (VideoHelper.isLiveEventOnAir(video)) {
                        if (videoDetailViewModel.updateVideoOnAir(video)) {
                            showPlayer();
                        }
                    } else {
                        changeFragment(isChromecastConntected());
                        videoDetailViewModel.checkOnAir(mVideoId).observe(VideoDetailActivity.this, new Observer<Video>() {

                            @Override
                            public void onChanged(@Nullable Video video) {
                                videoDetailViewModel.onCleared();
                                videoDetailViewModel.updateVideoOnAir(video);
                                showPlayer();
                            }
                        });
                    }
                    videoDetailViewModel.getVideo(mVideoId).removeObserver(this);
                }
            };
            videoDetailViewModel.getVideo(mVideoId).observe(this, videoObserver);
        }
    }
}
Also used : Video(com.zype.android.Db.Entity.Video) Observer(androidx.lifecycle.Observer) PlayerViewModel(com.zype.android.ui.player.PlayerViewModel) Nullable(androidx.annotation.Nullable)

Example 32 with Video

use of com.zype.android.Db.Entity.Video in project zype-android by zype.

the class VideoLiveData method handleVideo.

@Subscribe
public void handleVideo(VideoEvent event) {
    Logger.d("handleVideo()");
    VideoData data = event.getEventData().getModelData().getVideoData();
    Video video = DbHelper.videoDataToVideoEntity(data);
    if (checkOnAir) {
        if ((getValue() == null || getValue().onAir == 0) && video.onAir == 1) {
            setValue(video);
        } else {
            if (getValue() != null) {
                Logger.d("handleVideo(): videoId=" + video.id + ", onAir=" + getValue().onAir);
            }
        }
    } else {
        setValue(video);
    }
}
Also used : Video(com.zype.android.Db.Entity.Video) VideoData(com.zype.android.webapi.model.video.VideoData) Subscribe(com.squareup.otto.Subscribe)

Example 33 with Video

use of com.zype.android.Db.Entity.Video in project zype-android by zype.

the class PlayerFragment method showNotification.

public void showNotification() {
    Logger.d("showNotification()");
    if (player == null) {
        return;
    }
    Video video = videoViewModel.getVideoSync();
    if (video != null) {
        // String title = video.getTitle();
        // 
        // Intent notificationIntent;
        // Bundle bundle = new Bundle();
        // bundle.putString(BundleConstants.VIDEO_ID, video.id);
        // notificationIntent = new Intent(getActivity(), VideoDetailActivity.class);
        // notificationIntent.putExtras(bundle);
        // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        // 
        // PendingIntent intent = PendingIntent.getActivity(getActivity(), 0,
        // notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        // 
        // NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity(),
        // ZypeApp.NOTIFICATION_CHANNEL_ID);
        // builder.setContentIntent(intent)
        // .setContentTitle(getActivity().getString(R.string.app_name))
        // .setContentText(title)
        // .setSmallIcon(R.drawable.ic_background_playback)
        // .setPriority(NotificationCompat.PRIORITY_MAX)
        // .setAutoCancel(true)
        // .setOngoing(true)
        // .setWhen(0);
        // 
        // if (player != null) {
        // if (player.getPlayWhenReady()) {
        // builder.addAction(new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, "Pause",
        // MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(),
        // PlaybackStateCompat.ACTION_PLAY_PAUSE)));
        // }
        // else {
        // builder.addAction(new NotificationCompat.Action(R.drawable.ic_play_arrow_black_24dp, "Play",
        // MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(),
        // PlaybackStateCompat.ACTION_PLAY_PAUSE)));
        // }
        // }
        // builder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
        // .setMediaSession(mediaSession.getSessionToken())
        // .setShowCancelButton(true)
        // .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(),
        // PlaybackStateCompat.ACTION_STOP)));
        // 
        // NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
        // notificationManager.notify(ZypeApp.NOTIFICATION_ID, builder.build());
        Intent intent = new Intent(getActivity(), PlayerService.class);
        intent.setAction(player.getPlayWhenReady() ? PlayerService.ACTION_START_FOREGROUND_SERVICE_PLAY : PlayerService.ACTION_START_FOREGROUND_SERVICE_PAUSE);
        intent.putExtra(PlayerService.VIDEO_TITLE_EXTRA, video.getTitle());
        intent.putExtra(PlayerService.VIDEO_ID_EXTRA, video.id);
        intent.putExtra(PlayerService.MEDIA_SESSION_TOKEN_EXTRA, mediaSession.getSessionToken());
        getActivity().startService(intent);
        playerViewModel.setToBackground(true);
    }
}
Also used : Video(com.zype.android.Db.Entity.Video) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 34 with Video

use of com.zype.android.Db.Entity.Video in project zype-android by zype.

the class PlayerViewModel method savePlaybackPosition.

public void savePlaybackPosition(long position) {
    setPlaybackPosition(position);
    if (!TextUtils.isEmpty(videoId)) {
        Video video = repo.getVideoSync(videoId);
        if (video != null) {
            video.playTime = position;
            repo.updateVideo(video);
        }
    }
    isPlaybackPositionRestored = false;
}
Also used : Video(com.zype.android.Db.Entity.Video)

Example 35 with Video

use of com.zype.android.Db.Entity.Video in project zype-android by zype.

the class PlayerViewModel method getPlayerUrl.

// Player url
public LiveData<String> getPlayerUrl() {
    if (playerUrl == null) {
        playerUrl = new MutableLiveData<>();
    }
    if (playerUrl.getValue() == null) {
        if (isTrailer.getValue()) {
            setPlayerUrl(trailerUrl);
        } else {
            Video video = repo.getVideoSync(videoId);
            if (video != null) {
                video.playerAudioUrl = null;
                video.playerVideoUrl = null;
                updatePlayerUrl(video);
            }
            loadPlayer();
        }
    }
    return playerUrl;
}
Also used : Video(com.zype.android.Db.Entity.Video)

Aggregations

Video (com.zype.android.Db.Entity.Video)49 ArrayList (java.util.ArrayList)14 PlaylistVideo (com.zype.android.Db.Entity.PlaylistVideo)9 Playlist (com.zype.android.Db.Entity.Playlist)8 Subscribe (com.squareup.otto.Subscribe)6 FavoriteVideo (com.zype.android.Db.Entity.FavoriteVideo)6 List (java.util.List)6 NavigationHelper (com.zype.android.ui.NavigationHelper)5 VideoData (com.zype.android.webapi.model.video.VideoData)5 IZypeApiListener (com.zype.android.zypeapi.IZypeApiListener)5 ZypeApiResponse (com.zype.android.zypeapi.ZypeApiResponse)5 Application (android.app.Application)3 View (android.view.View)3 DataRepository (com.zype.android.DataRepository)3 VideoResponse (com.zype.android.zypeapi.model.VideoResponse)3 VideosResponse (com.zype.android.zypeapi.model.VideosResponse)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 TextUtils (android.text.TextUtils)2 ImageView (android.widget.ImageView)2