com.google.android.gms.cast.MediaMetadata Java Examples
The following examples show how to use
com.google.android.gms.cast.MediaMetadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CastUtils.java From UTubeTV with The Unlicense | 6 votes |
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by */ public static MediaInfo toMediaInfo(Bundle wrapper) { if (null == wrapper) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (null != images && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE)) .setContentType(wrapper.getString(KEY_CONTENT_TYPE)) .setMetadata(metaData) .build(); }
Example #2
Source File: CastUtils.java From UTubeTV with The Unlicense | 6 votes |
/** * Builds and returns a {@link Bundle} which contains a select subset of data in the * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this * container bundle to pass around from one activity to another. */ public static Bundle fromMediaInfo(MediaInfo info) { if (null == info) { return null; } MediaMetadata md = info.getMetadata(); Bundle wrapper = new Bundle(); wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE)); wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE)); wrapper.putString(KEY_URL, info.getContentId()); wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO)); wrapper.putString(KEY_CONTENT_TYPE, info.getContentType()); wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType()); if (null != md.getImages()) { ArrayList<String> urls = new ArrayList<String>(); for (WebImage img : md.getImages()) { urls.add(img.getUrl().toString()); } wrapper.putStringArrayList(KEY_IMAGES, urls); } return wrapper; }
Example #3
Source File: MediaData.java From Casty with MIT License | 6 votes |
MediaInfo createMediaInfo() { MediaMetadata mediaMetadata = new MediaMetadata(mediaType); if (!TextUtils.isEmpty(title)) mediaMetadata.putString(MediaMetadata.KEY_TITLE, title); if (!TextUtils.isEmpty(subtitle)) mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle); for (String imageUrl : imageUrls) { mediaMetadata.addImage(new WebImage(Uri.parse(imageUrl))); } return new MediaInfo.Builder(url) .setStreamType(streamType) .setContentType(contentType) .setStreamDuration(streamDuration) .setMetadata(mediaMetadata) .build(); }
Example #4
Source File: VideoCastControllerFragment.java From UTubeTV with The Unlicense | 6 votes |
private void updateMetadata() { String imageUrl = null; if (null == mSelectedMedia) { if (null != mMediaAuthService) { imageUrl = CastUtils.getImageUrl(mMediaAuthService.getMediaInfo(), 1); } } else { imageUrl = CastUtils.getImageUrl(mSelectedMedia, 1); } if (null != imageUrl) { showImage(imageUrl); } if (null == mSelectedMedia) { return; } MediaMetadata mm = mSelectedMedia.getMetadata(); mCastController.setLine1(mm.getString(MediaMetadata.KEY_TITLE)); boolean isLive = mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE; mCastController.adjustControllersForLiveStream(isLive); }
Example #5
Source File: CastOptionsProvider.java From CastVideos-android with Apache License 2.0 | 6 votes |
@Override public WebImage onPickImage(MediaMetadata mediaMetadata, int type) { if ((mediaMetadata == null) || !mediaMetadata.hasImages()) { return null; } List<WebImage> images = mediaMetadata.getImages(); if (images.size() == 1) { return images.get(0); } else { if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) { return images.get(0); } else { return images.get(1); } } }
Example #6
Source File: GoogleCastOptionsProvider.java From react-native-google-cast with MIT License | 6 votes |
@Override public WebImage onPickImage(MediaMetadata mediaMetadata, int type) { if ((mediaMetadata == null) || !mediaMetadata.hasImages()) { return null; } List<WebImage> images = mediaMetadata.getImages(); if (images.size() == 1) { return images.get(0); } else { if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) { return images.get(0); } else { return images.get(1); } } }
Example #7
Source File: CastOptionsProvider.java From DeviceConnect-Android with MIT License | 6 votes |
@Override public WebImage onPickImage(MediaMetadata mediaMetadata, int type) { if ((mediaMetadata == null) || !mediaMetadata.hasImages()) { return null; } List<WebImage> images = mediaMetadata.getImages(); if (images.size() == 1) { return images.get(0); } else { if (type == ImagePicker.IMAGE_TYPE_MEDIA_ROUTE_CONTROLLER_DIALOG_BACKGROUND) { return images.get(0); } else { return images.get(1); } } }
Example #8
Source File: CastPlayback.java From klingar with Apache License 2.0 | 6 votes |
private static MediaInfo toCastMediaMetadata(Track track, JSONObject customData) { MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK); mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.title()); mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.artistTitle()); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.artistTitle()); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.albumTitle()); WebImage image = new WebImage(new Uri.Builder().encodedPath(track.thumb()).build()); // First image is used by the receiver for showing the audio album art. mediaMetadata.addImage(image); // Second image is used by Cast Library when the cast dialog is clicked. mediaMetadata.addImage(image); //noinspection ResourceType return new MediaInfo.Builder(track.source()) .setContentType(MIME_TYPE_AUDIO_MPEG) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(mediaMetadata) .setCustomData(customData) .build(); }
Example #9
Source File: VideoCastManager.java From android with Apache License 2.0 | 6 votes |
/** * Updates the information and state of a MiniController. * * @throws TransientNetworkDisconnectionException * @throws NoConnectionException */ private void updateMiniController(IMiniController controller) throws TransientNetworkDisconnectionException, NoConnectionException { checkConnectivity(); checkRemoteMediaPlayerAvailable(); if (mRemoteMediaPlayer.getStreamDuration() > 0 || isRemoteStreamLive()) { MediaInfo mediaInfo = getRemoteMediaInformation(); MediaMetadata mm = mediaInfo.getMetadata(); controller.setStreamType(mediaInfo.getStreamType()); controller.setPlaybackStatus(mState, mIdleReason); controller.setSubTitle(mContext.getResources().getString(R.string.casting_to_device, mDeviceName)); controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE)); if (!mm.getImages().isEmpty()) { controller.setIcon(mm.getImages().get(0).getUrl()); } } }
Example #10
Source File: VideoCastControllerFragment.java From android with Apache License 2.0 | 6 votes |
private void updateMetadata() { String imageUrl = null; if (null == mSelectedMedia) { if (null != mMediaAuthService) { imageUrl = Utils.getImageUrl(mMediaAuthService.getMediaInfo(), 1); } } else { imageUrl = Utils.getImageUrl(mSelectedMedia, 1); } showImage(imageUrl); if (null == mSelectedMedia) { return; } MediaMetadata mm = mSelectedMedia.getMetadata(); mCastController.setLine1(null != mm.getString(MediaMetadata.KEY_TITLE) ? mm.getString(MediaMetadata.KEY_TITLE) : ""); boolean isLive = mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE; mCastController.adjustControllersForLiveStream(isLive); }
Example #11
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
private void startVideo() { MediaMetadata mediaMetadata = new MediaMetadata( MediaMetadata.MEDIA_TYPE_MOVIE ); mediaMetadata.putString( MediaMetadata.KEY_TITLE, getString( R.string.video_title ) ); MediaInfo mediaInfo = new MediaInfo.Builder( getString( R.string.video_url ) ) .setContentType( getString( R.string.content_type_mp4 ) ) .setStreamType( MediaInfo.STREAM_TYPE_BUFFERED ) .setMetadata( mediaMetadata ) .build(); try { mRemoteMediaPlayer.load( mApiClient, mediaInfo, true ) .setResultCallback( new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() { @Override public void onResult( RemoteMediaPlayer.MediaChannelResult mediaChannelResult ) { if( mediaChannelResult.getStatus().isSuccess() ) { mVideoIsLoaded = true; mButton.setText( getString( R.string.pause_video ) ); } } } ); } catch( Exception e ) { } }
Example #12
Source File: VinylCastService.java From vinyl-cast with MIT License | 6 votes |
private void updateCastSession() { if (((VinylCastApplication)getApplication()).getCastSessionManager().getCurrentCastSession() == null) { return; } if (((VinylCastApplication)getApplication()).getCastSessionManager().getCurrentCastSession().getRemoteMediaClient() == null) { return; } RemoteMediaClient remoteMediaClient = ((VinylCastApplication)getApplication()).getCastSessionManager().getCurrentCastSession().getRemoteMediaClient(); if (isRecording() && httpStreamServer != null) { MediaMetadata audioMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK); String url = httpStreamServer.getStreamUrl(); MediaInfo mediaInfo = new MediaInfo.Builder(url) .setContentType(httpStreamServer.getContentType()) .setStreamType(MediaInfo.STREAM_TYPE_LIVE) .setStreamDuration(MediaInfo.UNKNOWN_DURATION) .setMetadata(audioMetadata) .build(); Timber.d("Cast MediaInfo: " + mediaInfo); MediaLoadRequestData mediaLoadRequestData = new MediaLoadRequestData.Builder().setMediaInfo(mediaInfo).build(); remoteMediaClient.load(mediaLoadRequestData); } else { remoteMediaClient.stop(); } }
Example #13
Source File: GoogleCastDelegate.java From edx-app-android with Apache License 2.0 | 5 votes |
private MediaInfo buildMediaInfo(@NonNull DownloadEntry videoEntry, @NonNull String videoUrl) { final MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString(MediaMetadata.KEY_TITLE, videoEntry.title); movieMetadata.addImage(new WebImage(Uri.parse(videoEntry.videoThumbnail))); return new MediaInfo.Builder(videoUrl) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType("videos/*") .setMetadata(movieMetadata) .setStreamDuration(videoEntry.getDuration() * 1000) .build(); }
Example #14
Source File: Utils.java From android with Apache License 2.0 | 5 votes |
/** * Builds and returns a {@link Bundle} which contains a select subset of data in the * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this * container bundle to pass around from one activity to another. * * @param info * @return * @see <code>toMediaInfo()</code> */ public static Bundle fromMediaInfo(MediaInfo info) { if (null == info) { return null; } MediaMetadata md = info.getMetadata(); Bundle wrapper = new Bundle(); wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE)); wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE)); wrapper.putString(KEY_URL, info.getContentId()); wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO)); wrapper.putString(KEY_CONTENT_TYPE, info.getContentType()); wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType()); if (!md.getImages().isEmpty()) { ArrayList<String> urls = new ArrayList<String>(); for (WebImage img : md.getImages()) { urls.add(img.getUrl().toString()); } wrapper.putStringArrayList(KEY_IMAGES, urls); } JSONObject customData = info.getCustomData(); if (null != customData) { wrapper.putString(KEY_CUSTOM_DATA, customData.toString()); } return wrapper; }
Example #15
Source File: CastOptionsProvider.java From edx-app-android with Apache License 2.0 | 5 votes |
@Override public WebImage onPickImage(MediaMetadata mediaMetadata, @NonNull ImageHints imageHints) { if ((mediaMetadata == null) || !mediaMetadata.hasImages()) { return null; } return mediaMetadata.getImages().get(0); }
Example #16
Source File: MainActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { if( CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession() != null && CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession().getRemoteMediaClient() != null ) { RemoteMediaClient remoteMediaClient = CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession().getRemoteMediaClient(); if( remoteMediaClient.getMediaInfo() != null && remoteMediaClient.getMediaInfo().getMetadata() != null && mAdapter.getItem(position).equalsIgnoreCase( remoteMediaClient.getMediaInfo().getMetadata().getString(MediaMetadata.KEY_TITLE))) { startActivity(new Intent(this, ExpandedControlsActivity.class)); } else { MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metadata.putString(MediaMetadata.KEY_TITLE, mAdapter.getItem(position)); metadata.putString(MediaMetadata.KEY_SUBTITLE, "Subtitle"); metadata.addImage(new WebImage(Uri.parse(getString(R.string.movie_poster)))); metadata.addImage(new WebImage(Uri.parse(getString(R.string.movie_poster)))); MediaInfo mediaInfo = new MediaInfo.Builder(getString(R.string.movie_link)) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType("videos/mp4") .setMetadata(metadata) .build(); remoteMediaClient.load(mediaInfo, true, 0); } } else { startActivity(new Intent(this, MovieDetailActivity.class)); } }
Example #17
Source File: CastActivity.java From UTubeTV with The Unlicense | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cast); mCastManager = MainApplication.getCastManager(this); getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayUseLogoEnabled(false); getActionBar().setDisplayShowHomeEnabled(false); getActionBar().setDisplayShowTitleEnabled(false); setupMiniController(); setupCastListener(); MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "Animal Fats"); movieMetadata.putString(MediaMetadata.KEY_TITLE, "Stuff that Sucks"); movieMetadata.putString(MediaMetadata.KEY_STUDIO, "Google"); movieMetadata.addImage(new WebImage(Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images_480x270/ForBiggerEscapes.jpg"))); movieMetadata.addImage(new WebImage(Uri.parse("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images_780x1200/Escape-780x1200.jpg"))); mSelectedMedia = new MediaInfo.Builder("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4") .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType("video/mp4") .setMetadata(movieMetadata) .build(); View button = findViewById(R.id.play_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { togglePlayback(); } }); }
Example #18
Source File: VideoCastManager.java From UTubeTV with The Unlicense | 5 votes |
/** * Updates the information and state of a MiniController. */ private void updateMiniController(IMiniController controller) throws TransientNetworkDisconnectionException, NoConnectionException { checkConnectivity(); checkRemoteMediaPlayerAvailable(); if (mRemoteMediaPlayer.getStreamDuration() > 0) { MediaInfo mediaInfo = getRemoteMediaInformation(); MediaMetadata mm = mediaInfo.getMetadata(); controller.setStreamType(mediaInfo.getStreamType()); controller.setPlaybackStatus(mState, mIdleReason); controller.setSubTitle(mContext.getResources() .getString(R.string.casting_to_device, mDeviceName)); controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE)); controller.setIcon(mm.getImages().get(0).getUrl()); } }
Example #19
Source File: CastUtils.java From UTubeTV with The Unlicense | 5 votes |
/** * Returns the URL of an image for the MediaInformation at the given level. Level should * be a number between 0 and <code>n - 1</code> where <code>n * </code> is the number of images for that given item. */ public static String getImageUrl(MediaInfo info, int level) { MediaMetadata mm = info.getMetadata(); if (null != mm && null != mm.getImages() && mm.getImages().size() > level) { return mm.getImages().get(level).getUrl().toString(); } return null; }
Example #20
Source File: VideoDetailsFragment.java From Loop with Apache License 2.0 | 5 votes |
private MediaInfo buildMediaInfo() { MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, video.getUser().getName()); movieMetadata.putString(MediaMetadata.KEY_TITLE, video.getName()); movieMetadata.addImage(new WebImage(Uri.parse(video.getThumbnailUrl()))); return new MediaInfo.Builder(videoUrl) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType("videos/mp4") .setMetadata(movieMetadata) .setStreamDuration(exoPlayer.getDuration() * 1000) .build(); }
Example #21
Source File: ChromeCastMediaPlayer.java From DeviceConnect-Android with MIT License | 5 votes |
/** * メディアをロードする. * * @param response レスポンス * @param url メディアのURL * @param title メディアのタイトル */ public void load(final Intent response, final String url, final String title) { MediaInfo mediaInfo; MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); mediaMetadata.putString(MediaMetadata.KEY_TITLE, title); String ext = MimeTypeMap.getFileExtensionFromUrl(url).toLowerCase(Locale.getDefault()); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext); if (mimeType == null || mimeType.isEmpty()) { mimeType = "application/octet-stream"; } mediaInfo = new MediaInfo.Builder(url).setContentType(mimeType) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(mediaMetadata).build(); if (mRemoteMediaPlayer != null) { try { mRemoteMediaPlayer .load(mController.getGoogleApiClient(), mediaInfo, false) .setResultCallback((result) -> { if (result.getStatus().isSuccess()) { mIsLoadEnable = true; } else { mIsLoadEnable = false; } mCallbacks.onChromeCastMediaPlayerResult(response, result, "load"); }); } catch (Exception e) { if (BuildConfig.DEBUG) { e.printStackTrace(); } mCallbacks.onChromeCastMediaPlayerResult(response, null, "load"); } } }
Example #22
Source File: LocalPlayerActivity.java From cast-videos-android with Apache License 2.0 | 5 votes |
private MediaInfo buildMediaInfo() { MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, mSelectedMedia.getStudio()); movieMetadata.putString(MediaMetadata.KEY_TITLE, mSelectedMedia.getTitle()); movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(0)))); movieMetadata.addImage(new WebImage(Uri.parse(mSelectedMedia.getImage(1)))); return new MediaInfo.Builder(mSelectedMedia.getUrl()) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType("videos/mp4") .setMetadata(movieMetadata) .setStreamDuration(mSelectedMedia.getDuration() * 1000) .build(); }
Example #23
Source File: LiveStreamActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
@Override protected Bundle getStreamArguments() { boolean autoPlay = true; Intent intent = getIntent(); ChannelInfo mChannelInfo = intent.getParcelableExtra(getResources().getString(R.string.intent_key_streamer_info)); int currentViewers = intent.getIntExtra(getResources().getString(R.string.intent_key_stream_viewers), -1); if (mChannelInfo == null) { try { CastContext sharedContext = Service.getShareCastContext(this); MediaInfo mediaInfo = null; if (sharedContext != null) { mediaInfo = sharedContext.getSessionManager().getCurrentCastSession().getRemoteMediaClient().getMediaInfo(); } if (mediaInfo != null) { MediaMetadata metadata = mediaInfo.getMetadata(); mChannelInfo = new Gson().fromJson(metadata.getString(getString(R.string.stream_fragment_streamerInfo)), new TypeToken<ChannelInfo>() { }.getType()); autoPlay = false; } } catch (Exception e) { e.printStackTrace(); } } Bundle args = new Bundle(); args.putParcelable(getString(R.string.stream_fragment_streamerInfo), mChannelInfo); args.putInt(getString(R.string.stream_fragment_viewers), currentViewers); args.putBoolean(getString(R.string.stream_fragment_autoplay), autoPlay); return args; }
Example #24
Source File: BaseActivity.java From SkyTube with GNU General Public License v3.0 | 4 votes |
public void playVideoOnChromecast(final YouTubeVideo video, final int position) { showLoadingSpinner(); if(video.getDescription() == null) { new GetVideoDescriptionTask(video, description -> { playVideoOnChromecast(video, position); }).executeInParallel(); } else { video.getDesiredStream(new GetDesiredStreamListener() { @Override public void onGetDesiredStream(StreamMetaData desiredStream) { if(mCastSession == null) return; Gson gson = new Gson(); final RemoteMediaClient remoteMediaClient = mCastSession.getRemoteMediaClient(); MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC); metadata.putInt(KEY_POSITION, position); metadata.putString(KEY_VIDEO, gson.toJson(video)); metadata.addImage(new WebImage(Uri.parse(video.getThumbnailUrl()))); MediaInfo currentPlayingMedia = new MediaInfo.Builder(desiredStream.getUri().toString()) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType(desiredStream.getFormat().mimeType) .setMetadata(metadata) .build(); MediaLoadOptions options = new MediaLoadOptions.Builder().setAutoplay(true).setPlayPosition(0).build(); remoteMediaClient.load(currentPlayingMedia, options); chromecastMiniControllerFragment.init(remoteMediaClient, currentPlayingMedia, position); chromecastControllerFragment.init(remoteMediaClient, currentPlayingMedia, position); // If the Controller panel isn't visible, setting the progress of the progressbar in the mini controller won't // work until the panel is visible, so do it as soon as the sliding panel is visible. Adding this listener when // the panel is not hidden will lead to a java.util.ConcurrentModificationException the next time a video is // switching from local playback to chromecast, so we should only do this if the panel is hidden. if(slidingLayout.getPanelState() == SlidingUpPanelLayout.PanelState.HIDDEN) { slidingLayout.addPanelSlideListener(getOnPanelDisplayed(position, video.getDurationInSeconds()*1000)); } } @Override public void onGetDesiredStreamError(String errorMessage) { if (errorMessage != null) { if(chromecastLoadingSpinner != null) chromecastLoadingSpinner.setVisibility(View.GONE); new AlertDialog.Builder(BaseActivity.this) .setMessage(errorMessage) .setTitle(R.string.error_video_play) .setCancelable(false) .setPositiveButton(R.string.ok, (dialog, which) -> { }) .show(); } } }); } }
Example #25
Source File: MediaInfoBuilder.java From react-native-google-cast with MIT License | 4 votes |
public static @NonNull MediaInfo buildMediaInfo(@NonNull ReadableMap parameters) { MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); String title = ReadableMapUtils.getString(parameters, "title"); if (title != null) { movieMetadata.putString(MediaMetadata.KEY_TITLE, title); } String subtitle = ReadableMapUtils.getString(parameters, "subtitle"); if (subtitle != null) { movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, subtitle); } String studio = ReadableMapUtils.getString(parameters, "studio"); if (studio != null) { movieMetadata.putString(MediaMetadata.KEY_STUDIO, studio); } String imageUrl = ReadableMapUtils.getString(parameters, "imageUrl"); if (imageUrl != null) { movieMetadata.addImage(new WebImage(Uri.parse(imageUrl))); } String posterUrl = ReadableMapUtils.getString(parameters, "posterUrl"); if (posterUrl != null) { movieMetadata.addImage(new WebImage(Uri.parse(posterUrl))); } String mediaUrl = ReadableMapUtils.getString(parameters, "mediaUrl"); if (mediaUrl == null) { throw new IllegalArgumentException("mediaUrl option is required"); } Boolean isLive = ReadableMapUtils.getBoolean(parameters, "isLive"); int streamType = isLive != null && isLive ? MediaInfo.STREAM_TYPE_LIVE : MediaInfo.STREAM_TYPE_BUFFERED; MediaInfo.Builder builder = new MediaInfo.Builder(mediaUrl) .setStreamType(streamType) .setMetadata(movieMetadata); String contentType = ReadableMapUtils.getString(parameters, "contentType"); builder = builder.setContentType(contentType != null ? contentType : DEFAULT_CONTENT_TYPE); Map<?, ?> customData = ReadableMapUtils.getMap(parameters, "customData"); if (customData != null) { builder = builder.setCustomData(new JSONObject(customData)); } Integer streamDuration = ReadableMapUtils.getInt(parameters, "streamDuration"); if (streamDuration != null) { builder = builder.setStreamDuration(streamDuration); } ReadableMap textTrackStyle = ReadableMapUtils.getReadableMap(parameters, "textTrackStyle"); if (textTrackStyle != null) { builder = builder.setTextTrackStyle(buildTextTrackStyle(textTrackStyle)); } return builder.build(); }
Example #26
Source File: QueueListAdapter.java From CastVideos-android with Apache License 2.0 | 4 votes |
@Override public void onBindViewHolder(final QueueItemViewHolder holder, int position) { Log.d(TAG, "[upcoming] onBindViewHolder() for position: " + position); final MediaQueueItem item = mProvider.getItem(position); holder.mContainer.setTag(R.string.queue_tag_item, item); holder.mPlayPause.setTag(R.string.queue_tag_item, item); holder.mPlayUpcoming.setTag(R.string.queue_tag_item, item); holder.mStopUpcoming.setTag(R.string.queue_tag_item, item); // Set listeners holder.mContainer.setOnClickListener(mItemViewOnClickListener); holder.mPlayPause.setOnClickListener(mItemViewOnClickListener); holder.mPlayUpcoming.setOnClickListener(mItemViewOnClickListener); holder.mStopUpcoming.setOnClickListener(mItemViewOnClickListener); MediaInfo info = item.getMedia(); MediaMetadata metaData = info.getMetadata(); holder.mTitleView.setText(metaData.getString(MediaMetadata.KEY_TITLE)); holder.mDescriptionView.setText(metaData.getString(MediaMetadata.KEY_SUBTITLE)); if (!metaData.getImages().isEmpty()) { String url = metaData.getImages().get(0).getUrl().toString(); mImageLoader = CustomVolleyRequest.getInstance(mAppContext) .getImageLoader(); mImageLoader.get(url, ImageLoader.getImageListener(holder.mImageView, 0, 0)); holder.mImageView.setImageUrl(url, mImageLoader); } holder.mDragHandle.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return false; } }); if (item == mProvider.getCurrentItem()) { holder.updateControlsStatus(QueueItemViewHolder.CURRENT); updatePlayPauseButtonImageResource(holder.mPlayPause); } else if (item == mProvider.getUpcomingItem()) { holder.updateControlsStatus(QueueItemViewHolder.UPCOMING); } else { holder.updateControlsStatus(QueueItemViewHolder.NONE); holder.mPlayPause.setVisibility(View.GONE); } }
Example #27
Source File: LocalPlayerActivity.java From CastVideos-android with Apache License 2.0 | 4 votes |
private void setupActionBar() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(mSelectedMedia.getMetadata().getString(MediaMetadata.KEY_TITLE)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
Example #28
Source File: StreamFragment.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 4 votes |
/** * Sends the URL to a chromecast (Or android TV) if it is connected. * * @param videoURL */ private void playOnCast(String videoURL) { //ToDo: We probably need to make a custom Cast receiver to play a link from Twitch. As Twitch doesnt allow third party receivers to play link from another origin // Use https://www.udacity.com/course/progress#!/c-ud875B and // https://github.com/googlecast/CastReferencePlayer try { String logoImageUrl = mChannelInfo.getLogoURLString(); String streamerName = mChannelInfo.getDisplayName(); if (mCastContext != null && mCastContext.getCastState() == CastState.CONNECTED) { MediaMetadata mediaMetadata = new MediaMetadata(); mediaMetadata.putString(getString(R.string.stream_fragment_vod_id), vodId); mediaMetadata.putInt(getString(R.string.stream_fragment_vod_length), vodLength); mediaMetadata.putString(getString(R.string.stream_fragment_streamerInfo), new Gson().toJson(mChannelInfo)); mediaMetadata.putString(MediaMetadata.KEY_TITLE, streamerName); if (logoImageUrl != null) { mediaMetadata.addImage(new WebImage(Uri.parse(logoImageUrl))); } MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(videoURL) .setMetadata(mediaMetadata) .setContentType("application/x-mpegURL"); if (vodId == null) { mediaBuilder .setStreamType(MediaInfo.STREAM_TYPE_LIVE) .setStreamDuration(MediaInfo.UNKNOWN_DURATION); } else { mediaBuilder .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setStreamDuration(vodLength / 1000); } CastSession session = mCastContext.getSessionManager().getCurrentCastSession(); if (session != null) { checkChromecastConnection(); session.getRemoteMediaClient().load(mediaBuilder.build(), true, 0); } } } catch (Exception e) { e.printStackTrace(); } }
Example #29
Source File: Utils.java From android with Apache License 2.0 | 3 votes |
/** * Returns the URL of an image for the {@link MediaInformation} at the given level. Level should * be a number between 0 and <code>n - 1</code> where <code>n * </code> is the number of images for that given item. * * @param info * @param level * @return */ public static String getImageUrl(MediaInfo info, int level) { MediaMetadata mm = info.getMetadata(); if (null != mm && mm.getImages().size() > level) { return mm.getImages().get(level).getUrl().toString(); } return null; }