Search in sources :

Example 1 with MediaInfo

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);
                }
            }
        });
    }
}
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 MediaInfo

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);
        }
    });
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError)

Example 3 with MediaInfo

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));
    }
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ImageInfo(com.connectsdk.core.ImageInfo)

Example 4 with MediaInfo

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);
}
Also used : MediaInfo(com.connectsdk.core.MediaInfo) ArrayList(java.util.ArrayList) ImageInfo(com.connectsdk.core.ImageInfo)

Example 5 with MediaInfo

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;
    }
}
Also used : RemoteMediaPlayer(com.amazon.whisperplay.fling.media.controller.RemoteMediaPlayer) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) JSONException(org.json.JSONException) ExecutionException(java.util.concurrent.ExecutionException) MediaInfo(com.connectsdk.core.MediaInfo) JSONObject(org.json.JSONObject) MediaPlayerInfo(com.amazon.whisperplay.fling.media.service.MediaPlayerInfo) FireTVServiceError(com.connectsdk.service.command.FireTVServiceError) ArrayList(java.util.ArrayList) List(java.util.List) ImageInfo(com.connectsdk.core.ImageInfo)

Aggregations

MediaInfo (com.connectsdk.core.MediaInfo)6 ImageInfo (com.connectsdk.core.ImageInfo)4 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)3 ArrayList (java.util.ArrayList)2 JSONObject (org.json.JSONObject)2 SubtitleWrapper (butter.droid.base.providers.subs.model.SubtitleWrapper)1 RemoteMediaPlayer (com.amazon.whisperplay.fling.media.controller.RemoteMediaPlayer)1 MediaPlayerInfo (com.amazon.whisperplay.fling.media.service.MediaPlayerInfo)1 PlayStateStatus (com.connectsdk.service.capability.MediaControl.PlayStateStatus)1 MediaPlayer (com.connectsdk.service.capability.MediaPlayer)1 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)1 FireTVServiceError (com.connectsdk.service.command.FireTVServiceError)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1