Casting an image shows media controls in Notification, MiniControllerFragment and ExpandedControllerActivity - android

My application has Videos, Audios and Photos. I'm successfully able to cast all three of them. However when I cast an image, the minicontrollerfragment, Notification and ExpandedControllerActivity shows video controls.
When I click play/pause button it just keeps spinning round for photo.
Is there a way where I can disable it for images? I looked up everywhere but for some reason I was not able to find a single example of Photo.
Any help would be appreciated.
Thank you.
Here is the code for CastOptionsProvider.
#Override
public CastOptions getCastOptions(Context context) {
NotificationOptions notificationOptions = new NotificationOptions.Builder()
.setTargetActivityClassName(ExpandedControlsActivity.class.getName())
.setActions(Arrays.asList(MediaIntentReceiver.ACTION_REWIND,MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK, MediaIntentReceiver.ACTION_FORWARD, MediaIntentReceiver.ACTION_STOP_CASTING), new int[]{1,2,3})
.build();
CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
.setNotificationOptions(notificationOptions)
.setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
.build();
CastOptions castOptions = new CastOptions.Builder()
.setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
.setCastMediaOptions(mediaOptions)
.build();
return castOptions;
}
This is how I cast an image:
MediaMetadata photoMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
photoMetadata.putString(MediaMetadata.KEY_TITLE, "Casting to " + mCastSession.getCastDevice().getFriendlyName());
photoMetadata.addImage(new WebImage(Uri.parse(photoItem.getImageUrl())));
MediaInfo mediaInfo = new MediaInfo.Builder(photoItem.getImageUrl())
.setContentType("image/jpeg")
.setMetadata(photoMetadata)
.setStreamDuration(0)
.setStreamType(MediaInfo.STREAM_TYPE_NONE)
.build();
MediaLoadOptions mediaLoadOptions = new MediaLoadOptions.Builder()
.setAutoplay(true)
.setPlayPosition(0)
.build();
RemoteMediaClient remoteMediaClient = mCastSession.getRemoteMediaClient();
remoteMediaClient.load(mediaInfo, mediaLoadOptions);

You can use Default Media Receiver (CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) to give it a try as a default receiver, otherwise you need to create your own.
Inside your CastOptionProvider, create a CastOptions like below
new CastOptions.Builder()
.setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
.setCastMediaOptions(mediaOptions)
.build();

Related

How to post through Facebook Open Graph for game

I am developing some quiz app, and want to post player's achievement on facebook.
Since I want to post the image for the achievement and Link Share of facebook doesn't support add image any more, I decided to use Open Graph.
I succeeded to post with example source for the object type of "fitness.course", but still have troubles with the object type of "game.achievement".
Share Dialog shows up, and seems OK until I click post button. But, after clicking post button, I cannot find the post on my facebook wall.
Here is my source code.
// Set image with the image on the file path
Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setUserGenerated(true)
.build();
// set object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "game.achievement")
.putString("og:title", "App Name")
.putString("og:description", "You achieved Golden madal")
.putInt("game:point", 100)
.build();
// set action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("games.achieves")
.putObject("game.achievement", object)
.putPhoto("image", photo)
.build();
// set content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("game.achievement")
.setAction(action)
.build();
mShareDialog.show(content);
For your information, the below is the example source code I succeeded with
// Set image with the image on the file path
Bitmap image = BitmapFactory.decodeFile(finalImageFilePath);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.setUserGenerated(true)
.build();
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "App Name")
.putString("og:description", "You achieved Golden madal")
.putInt("fitness:duration:value", 100)
.putString("fitness:duration:units", "s")
.putInt("fitness:distance:value", 12)
.putString("fitness:distance:units", "km")
.putInt("fitness:speed:value", 5)
.putString("fitness:speed:units", "m/s")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("fitness:course", object)
.putPhoto("image", photo)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
Thanks a lot in advance for your efforts.
I think I have got the reason for this. It is so disappointing. Open Graph for game.achievement seems to have been depreciated. See the link https://developers.facebook.com/docs/games/services/scores-achievements?locale=en_US
The Scores API and Achievements API are slated for deprecation. As of
April 4, 2018, they will only return empty data sets and will be
deprecated in the near future. Please see the changelog for more
information.
Also facebook depreciated Custom Open Graph. See the link https://developers.facebook.com/docs/sharing/opengraph/custom-open-graph-deprecation

Unable to some videos in chrome cast

I am using CastCompanionLibrary-android for chromecast integration.
I am going to show few methods of chromecast integration
first one is configuration initalization in application cast
private void initchromecast() {
String applicationId = getString(R.string.app_id);
// Build a CastConfiguration object and initialize VideoCastManager
CastConfiguration options = new CastConfiguration.Builder(applicationId)
.enableAutoReconnect()
.enableCaptionManagement()
.enableDebug()
.enableLockScreen()
.enableNotification()
.enableWifiReconnection()
.setCastControllerImmersive(true)
.setLaunchOptions(false, Locale.getDefault())
.setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_DISABLED)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_REWIND, false)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
.addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true)
.setForwardStep(10)
.build();
VideoCastManager.initialize(this, options);
}
and TO pass meta data
private void loadRemoteMedia(int position, boolean autoPlay) {
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_TITLE, TITLE);
MediaInfo mediaInfo = new MediaInfo.Builder(
path)
.setContentType("application/x-mpegURL")
.setStreamType(MediaInfo.STREAM_TYPE_LIVE)
.setMetadata(mediaMetadata)
.setStreamDuration(MediaInfo.UNKNOWN_DURATION)
.build();
mCastManager.startVideoCastControllerActivity(getActivity(), mediaInfo, position, autoPlay);
}
Now my question is in below cod when i pass CastCompanion sample id 4F8B3483 ,i can successfully cast most of the videos but when i put my sample application reciver id some of the videos which works with their id does not work with mine.
For example http://iptvcanales.com/xw/peliculas.php?movie=006 url works with CastCompanion reciver id but not with mine id in my code.

No Preview When Publishing a Open Graph Common Action (Listen) to Facebook from an Android App

After a failed attempt to create my custom story in Facebook (see here)
I decided to use the "Listen" Open Graph common action pre-defined by Facebook. Here's my code:
// Facebook
mImageButtonShareOnFacebook = (ImageButton)view.findViewById(R.id.shareOnFacebook);
mImageButtonShareOnFacebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(_albumCover)
.setUserGenerated(true)
.build();
// Create an object
String fbAppId = getActivity().getString(R.string.facebook_app_id);
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("fb:app_id", fbAppId)
.putString("og:type", "music.song")
.putString("og:title", _title + " by " + _artist + " in XYZ Radio " + channel.getName() + " channel")
.putString("og:site_name", "XYZ Radio")
.putPhoto("og:image", photo)
.build();
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("music.listens")
.putObject("song", object)
.build();
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("song")
.setAction(action)
.build();
ShareDialog.show(NowPlayingFragment.this, content);
}
});
And here's what I am getting:
The published post seems be correct, though.
So, why am I getting that "A preview will be added after you post this link to..." message? Is that the default behaviour or what am I missing? Thanks in advance...
I believe this is by design, read more about pre-caching here:
When content is shared for the first time, the Facebook crawler will
scrape and cache the metadata from the URL shared. The crawler has to
see an image at least once before it can be rendered. This means that
the first person who shares a piece of content won't see a rendered
image.
I believe a similar concept applies for OG previews.

MediaMetadataCompat Extras

Is there any way to use extras with the MediaMetadataCompat from the support library?
Using the MediaMetadata I can set extras, but with the compat one I cannot.
Hope it helps.
import android.support.v4.media.session.MediaSessionCompat;
private MediaSessionCompat mMediaSession;
//init mediasesson
mMediaSession = new MediaSessionCompat(getApplicationContext(), "AudioPlayer",new ComponentName(this, HeadsetNotificationBroadcast.class), null);
//set the metadata
mMediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getSongDataHelper().getAlbumArt())
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getSongDataHelper().getArtist())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getSongDataHelper().getAlbum())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, getSongDataHelper().getTitle())
.build());
I have copy-pasted our code. Please tell me if you can understand it.
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle().toString());
mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle().toString());
mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
WebImage image = new WebImage(new Uri.Builder().encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
// First image is used by the receiver for showing the audio album art.
mediaMetadata.addImage(image);
// Second image is used by Cast Companion Library on the full screen activity that is shown
// when the cast dialog is clicked.
mediaMetadata.addImage(image);
return new MediaInfo.Builder(
track.getDescription().getExtras().getString(MutableMediaMetadataCompat.
METADATA_KEY_TRACK_SOURCE)).setContentType(
MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).setCustomData(customData).build();
}

Facebook Open Graph stories api v4.0

Im developing an android app and already connected everything to facebook and sucessfully shared a dialog and liked a page. Now i would like to post to feed using open graph api because i wanted to post everything in my own format, a image, title, coordinates and a small description.
Ive already created the custom open graph storie but i cant manage to make this work.
The share dialog opens and closes instantly
Namespace is roteiroobidos
Actiontype is Share
Object type is Interesting_place
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "obidosroteiro.share")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("obidosroteiro.share") //If i try to change any of these "share" the share dialog would not even open
.putObject("obidosroteiro:share", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("obidosroteiro:share")
.setAction(action)
.build();
Thanks
You have to change the way that you are calling your object/action using : instead of .
Also the setPreviewPropertyName() should contain the name of your object, in this case share.
Change to this:
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "obidosroteiro:share")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("obidosroteiro:share") //If i try to change any of these "share" the share dialog would not even open
.putObject("obidosroteiro:share", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("share")
.setAction(action)
.build();

Categories

Resources