Search in sources :

Example 1 with SubtitleWrapper

use of butter.droid.base.providers.subs.model.SubtitleWrapper in project butter-android by butterproject.

the class BeamManager method playVideo.

public void playVideo(StreamInfo info, final MediaPlayer.LaunchListener listener) {
    if (!mConnected) {
        listener.onError(ServiceCommandError.getError(503));
    }
    mStreamInfo = info;
    String location = info.getStreamUrl();
    if (!location.startsWith("http")) {
        BeamServer.setCurrentVideo(location);
        location = BeamServer.getVideoURL();
    }
    String subsLocation = null;
    SubtitleWrapper subtitle = info.getSubtitle();
    if (subtitle != null && subtitle.getFileUri() != null) {
        BeamServer.setCurrentSubs(subtitle.getFileUri().getPath());
        if (mCurrentDevice.hasCapability(MediaPlayer.Subtitles_Vtt)) {
            subsLocation = BeamServer.getSubsURL(BeamServer.VTT);
        } else if (mCurrentDevice.hasCapability(MediaPlayer.Subtitles_Srt)) {
            subsLocation = BeamServer.getSubsURL(BeamServer.SRT);
        }
    } else {
        BeamServer.removeSubs();
    }
    try {
        URL url = new URL(location);
        URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
        location = uri.toString();
        if (subsLocation != null) {
            URL subsUrl = new URL(subsLocation);
            URI subsUri = new URI(subsUrl.getProtocol(), subsUrl.getUserInfo(), subsUrl.getHost(), subsUrl.getPort(), subsUrl.getPath(), subsUrl.getQuery(), subsUrl.getRef());
            subsLocation = subsUri.toString();
        }
    } catch (MalformedURLException | URISyntaxException e) {
        e.printStackTrace();
    }
    String title = info.getFullTitle();
    String imageUrl = info.getPosterImage() == null ? "https://butterproject.org/images/header-logo.png" : info.getPosterImage();
    // String url, String mimeType, String title, String description, String iconSrc, boolean shouldLoop, LaunchListener listener
    if (mCurrentDevice != null) {
        MediaInfo mediaInfo = new MediaInfo(location, subsLocation, "video/mp4", title, "");
        mediaInfo.addImages(new ImageInfo(imageUrl));
        mCurrentDevice.getCapability(MediaPlayer.class).playMedia(mediaInfo, false, new MediaPlayer.LaunchListener() {

            @Override
            public void onSuccess(MediaPlayer.MediaLaunchObject object) {
                mLaunchSession = object.launchSession;
                if (listener != null) {
                    listener.onSuccess(object);
                }
            }

            @Override
            public void onError(ServiceCommandError error) {
                Timber.e(error.getMessage());
                if (listener != null) {
                    listener.onError(error);
                }
            }
        });
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) MediaInfo(com.connectsdk.core.MediaInfo) ImageInfo(com.connectsdk.core.ImageInfo) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper) MediaPlayer(com.connectsdk.service.capability.MediaPlayer)

Example 2 with SubtitleWrapper

use of butter.droid.base.providers.subs.model.SubtitleWrapper in project butter-android by butterproject.

the class PlayerManager method externalPlayerIntent.

@Nullable
public Intent externalPlayerIntent(@NonNull StreamInfo streamInfo) {
    final String defaultPlayer = preferencesHandler.getDefaultPlayer();
    if (!StringUtils.isEmpty(defaultPlayer)) {
        String[] playerData = defaultPlayer.split(DELIMITER);
        if (playerData.length > 1) {
            Intent intent = new Intent();
            SubtitleWrapper subtitle = streamInfo.getSubtitle();
            if (subtitle != null && subtitle.getFileUri() != null) {
                File subsLocation = new File(subtitle.getFileUri().getPath());
                BeamServer.setCurrentSubs(subsLocation);
                intent.putExtra("subs", new Uri[] { subtitle.getFileUri() });
                if (subtitle.getSubtitle() != null) {
                    intent.putExtra("subs.name", new String[] { subtitle.getSubtitle().getName() });
                }
            }
            BeamServer.setCurrentVideo(streamInfo.getStreamUrl());
            BeamServerService.getServer().start();
            intent.setClassName(playerData[1], playerData[0]);
            intent.setAction(Intent.ACTION_VIEW);
            // TODO: 7/29/17 Actual mime type!
            intent.setDataAndType(Uri.parse(BeamServer.getVideoURL()), "video/mp4");
            intent.putExtra(Intent.EXTRA_TITLE, streamInfo.getFullTitle());
            return intent;
        }
    }
    return null;
}
Also used : Intent(android.content.Intent) File(java.io.File) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper) Nullable(android.support.annotation.Nullable)

Example 3 with SubtitleWrapper

use of butter.droid.base.providers.subs.model.SubtitleWrapper in project butter-android by butterproject.

the class StreamPlayerPresenterImpl method loadSubtitle.

private void loadSubtitle() {
    SubtitleWrapper subtitle = streamInfo.getSubtitle();
    MediaWrapper media = streamInfo.getMedia();
    SubsProvider provider = providerManager.getSubsProvider(media.getProviderId());
    subtitleManager.downloadSubtitle(provider, media.getMedia(), subtitle).observeOn(AndroidSchedulers.mainThread()).subscribe(new MaybeObserver<SubtitleWrapper>() {

        @Override
        public void onSubscribe(final Disposable d) {
            disposeSubs();
            subsDisposable = d;
        }

        @Override
        public void onSuccess(final SubtitleWrapper subs) {
            loadSubs(subs.getFileUri());
        }

        @Override
        public void onError(final Throwable e) {
            // TODO show error loading subs
            Timber.d("Error loading subs");
        }

        @Override
        public void onComplete() {
            Timber.d("Maybe empty");
        }
    });
}
Also used : MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) Disposable(io.reactivex.disposables.Disposable) SubsProvider(butter.droid.provider.subs.SubsProvider) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper)

Example 4 with SubtitleWrapper

use of butter.droid.base.providers.subs.model.SubtitleWrapper in project butter-android by butterproject.

the class TVShowDetailPresenterImpl method startTorrent.

private void startTorrent(final MediaWrapper episode, final Torrent torrent) {
    // Load default subtitles
    StreamInfo info = new StreamInfo(torrent, episode, item, new SubtitleWrapper());
    view.torrentSelected(info);
}
Also used : StreamInfo(butter.droid.base.providers.media.model.StreamInfo) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper)

Example 5 with SubtitleWrapper

use of butter.droid.base.providers.subs.model.SubtitleWrapper in project butter-android by butterproject.

the class EpisodeDialogFragment method playClick.

@OnClick(R.id.play_button)
public void playClick() {
    smoothDismiss();
    // TODO parent
    UiSubItem selectedSub = this.selectedSub;
    final SubtitleWrapper subtitleWrapper;
    if (selectedSub != null) {
        subtitleWrapper = new SubtitleWrapper(selectedSub.getSubtitle());
    } else {
        subtitleWrapper = null;
    }
    // TODO use pare presenter
    StreamInfo streamInfo = new StreamInfo(selectedTorrent, new MediaWrapper(episode, mediaMeta), null, subtitleWrapper);
    ((FragmentListener) getActivity()).playStream(streamInfo);
}
Also used : MediaWrapper(butter.droid.base.providers.media.model.MediaWrapper) UiSubItem(butter.droid.ui.media.detail.model.UiSubItem) StreamInfo(butter.droid.base.providers.media.model.StreamInfo) SubtitleWrapper(butter.droid.base.providers.subs.model.SubtitleWrapper) OnClick(butterknife.OnClick)

Aggregations

SubtitleWrapper (butter.droid.base.providers.subs.model.SubtitleWrapper)9 MediaWrapper (butter.droid.base.providers.media.model.MediaWrapper)4 StreamInfo (butter.droid.base.providers.media.model.StreamInfo)4 UiSubItem (butter.droid.ui.media.detail.model.UiSubItem)3 Disposable (io.reactivex.disposables.Disposable)3 SubsProvider (butter.droid.provider.subs.SubsProvider)2 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Nullable (android.support.annotation.Nullable)1 TextUtils (android.text.TextUtils)1 R (butter.droid.R)1 PreferencesHandler (butter.droid.base.content.preferences.PreferencesHandler)1 MediaDisplayManager (butter.droid.base.manager.internal.media.MediaDisplayManager)1 ProviderManager (butter.droid.base.manager.internal.provider.ProviderManager)1 PlayerManager (butter.droid.base.manager.internal.vlc.PlayerManager)1 YouTubeManager (butter.droid.base.manager.internal.youtube.YouTubeManager)1 Genre (butter.droid.provider.base.filter.Genre)1 Format (butter.droid.provider.base.model.Format)1 Movie (butter.droid.provider.base.model.Movie)1 Streamable (butter.droid.provider.base.model.Streamable)1