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);
}
}
});
}
}
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;
}
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");
}
});
}
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);
}
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);
}
Aggregations