use of com.connectsdk.core.MediaInfo 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 com.connectsdk.core.MediaInfo in project butter-android by butterproject.
the class DLNAService method getMediaInfo.
@Override
public void getMediaInfo(final MediaInfoListener listener) {
getPositionInfo(new PositionInfoListener() {
@Override
public void onGetPositionInfoSuccess(final String positionInfoXml) {
Util.runInBackground(new Runnable() {
@Override
public void run() {
String baseUrl = "http://" + getServiceDescription().getIpAddress() + ":" + getServiceDescription().getPort();
String trackMetaData = parseData(positionInfoXml, "TrackMetaData");
MediaInfo info = DLNAMediaInfoParser.getMediaInfo(trackMetaData, baseUrl);
Util.postSuccess(listener, info);
}
});
}
@Override
public void onGetPositionInfoFailed(ServiceCommandError error) {
Util.postError(listener, error);
}
});
}
use of com.connectsdk.core.MediaInfo in project butter-android by butterproject.
the class CastService method getMediaInfo.
@Override
public void getMediaInfo(MediaInfoListener listener) {
if (mMediaPlayer == null)
return;
if (mMediaPlayer.getMediaInfo() != null) {
String url = mMediaPlayer.getMediaInfo().getContentId();
String mimeType = mMediaPlayer.getMediaInfo().getContentType();
MediaMetadata metadata = mMediaPlayer.getMediaInfo().getMetadata();
String title = null;
String description = null;
ArrayList<ImageInfo> list = null;
if (metadata != null) {
title = metadata.getString(MediaMetadata.KEY_TITLE);
description = metadata.getString(MediaMetadata.KEY_SUBTITLE);
if (metadata.getImages() != null && metadata.getImages().size() > 0) {
String iconUrl = metadata.getImages().get(0).getUrl().toString();
list = new ArrayList<ImageInfo>();
list.add(new ImageInfo(iconUrl));
}
}
MediaInfo info = new MediaInfo(url, mimeType, title, description, list);
Util.postSuccess(listener, info);
} else {
Util.postError(listener, new ServiceCommandError(0, "Media Info is null", null));
}
}
use of com.connectsdk.core.MediaInfo in project butter-android by butterproject.
the class DLNAMediaInfoParser method getMediaInfo.
public static MediaInfo getMediaInfo(String str) {
String url = DLNAMediaInfoParser.getURL(str);
String title = DLNAMediaInfoParser.getTitle(str);
String mimeType = DLNAMediaInfoParser.getMimeType(str);
String description = DLNAMediaInfoParser.getArtist(str) + "\n" + DLNAMediaInfoParser.getAlbum(str);
String iconUrl = DLNAMediaInfoParser.getThumbnail(str);
ArrayList<ImageInfo> list = new ArrayList<ImageInfo>();
list.add(new ImageInfo(iconUrl));
return new MediaInfo(url, mimeType, title, description, list);
}
use of com.connectsdk.core.MediaInfo in project butter-android by butterproject.
the class FireTVService method getMediaInfo.
/**
* Get MediaInfo available only during playback otherwise returns an error
* @param listener
*/
@Override
public void getMediaInfo(final MediaInfoListener listener) {
final String error = "Error getting media info";
RemoteMediaPlayer.AsyncFuture<MediaPlayerInfo> asyncFuture = null;
try {
asyncFuture = remoteMediaPlayer.getMediaInfo();
handleAsyncFutureWithConversion(listener, asyncFuture, new ConvertResult<MediaInfo, MediaPlayerInfo>() {
@Override
public MediaInfo convert(MediaPlayerInfo data) throws JSONException {
JSONObject metaJson = null;
metaJson = new JSONObject(data.getMetadata());
List<ImageInfo> images = null;
if (metaJson.has(META_ICON_IMAGE)) {
images = new ArrayList<ImageInfo>();
images.add(new ImageInfo(metaJson.getString(META_ICON_IMAGE)));
}
MediaInfo mediaInfo = new MediaInfo(data.getSource(), metaJson.getString(META_MIME_TYPE), metaJson.getString(META_TITLE), metaJson.getString(META_DESCRIPTION), images);
return mediaInfo;
}
}, error);
} catch (Exception e) {
Util.postError(listener, new FireTVServiceError(error));
return;
}
}
Aggregations