How to set custom layout and font in Exoplayer notification? - android

I'm using PlayerNotificationManager for displaying playback notifications in my application. Everything is working fine but I want to add my application's logo in the notification with custom fonts.
I changed the play & pause buttons on the notification by adding drawables.xml. But can't find a way to change the font.
So, how can I change the default notification layout and characteristics that Exoplayer provides?
Edit:
I have seen this issue on Github which says that we need to extend PlayerNotificationManager in order to use custom layout. But I can't seem to get it working.
Here is my code:
private void setPlayerNotificationManager(Player player) {
playerNotificationManager = new PlayerNotificationManager(context, "123", 1234, mediaDescriptionAdapter);
playerNotificationManager.setUseNavigationActions(false);
playerNotificationManager.setUsePlayPauseActions(true);
playerNotificationManager.setRewindIncrementMs(0);
playerNotificationManager.setFastForwardIncrementMs(0);
//playerNotificationManager.setColor(Color.GREEN);
playerNotificationManager.setColorized(true);
playerNotificationManager.setUseChronometer(false);
playerNotificationManager.setSmallIcon(R.drawable.logo);
playerNotificationManager.setPlayer(player);
}

As said on the repo you need to extends the PlayerNotificationManager to do that you need to create this class and copy everything inside your project, and then add the layout you want to use as described in this link
You need to add your layout in the builder here

Related

Correct way to update notification actions

I have an app with media buttons and text in the notification that I want to update programatically. So I did this:
public void updateNotificatonIcons() {
ArrayList<NotificationCompat.Action> acts = NotificationBuilder.mActions;
acts.set(1, new NotificationCompat.Action((isPlaying) ? R.drawable.my_media_stop : R.drawable.my_media_play, "Stop", stopintent));
NotificationBuilder.mActions = acts;
NotificationManagerCompat.from(context).notify(1, NotificationBuilder.build());
}
The problem is that AndroidStudio complains about NotificationBuilder.mActions:
Builder.mActions can only be accessed from within the same library group prefix (referenced groupId=androidx.core with prefix androidx from groupId=Android)
I googled and added a #SuppressLint("RestrictedApi") before the method, and it works.
Is this the "correct" way of updating the notification? Is there a better way without the need of a #SupressLint?

Getting "Contents hidden" as replacement in custom layout public notification

I would like to set the italic "Contents hidden" message for a public notification manually.
Android seem to set "Contents hidden" automatically if only a VISIBILITY_PRIVATE notification without a public counterpart is presented.
Here, the setContent-parts are automatically replaced.
For an example from K9mail see screenshot 1.
However, I would like to use a custom layout for the public notification while letting the notification look similar (i.e., "Contents hidden").
It is a notification for a music player, which should provide buttons for pause and play next songs.
So, how can I either
access the (localized) value for "Contents hidden" that Android is actually using (not implementing it manually) or
tell Android to replace all "setContent"-parts automatically as if I would not provide a public notification.
Any suggestions?
For the sake of completeness - the issue is related with this pull request: https://github.com/gateship-one/odyssey/pull/120
Pretty simple just use:
String foo = mContext.getString(android.content.res.Resources.getSystem().getIdentifier("notification_hidden_text", "string", "android"));

Android TV PlaybackControlsRow

So building a new app specifically for the Android TV interface (lollipop leanback) and I'm using the PlaybackOverlayFragment that is provided by the framework which has a PlaybackControlsRow with all the usual controls on it.
The problem is, the default behavior is for the user to have to click the "Play" button to start the video and I want it to start automatically. That part is easy and I have it working but then the Play/Pause icons on the provided control are out of sync (showing play when should be pause) because the item was started outside of the events of clicking on that control.
Documentation is sparse on these framework elements and examining the class I can't find any public method that would allow me to put this control in the proper "mode" or tell it to display the play or pause icon myself.
Anyone with experience with these yet that would know how to do this?
In order to change the state of the button, even after adding your Actions to the Adapter, you'll need to notify the changes to the adapter that has your Action.
mPlayPauseAction.nextIndex(); // next index, if it was pause, it'll be play
notifyChanged(mPlayPauseAction);
// where notifyChanged(Action action) is:
private void notifyChanged(Action action) {
ArrayObjectAdapter adapter = mPrimaryActionsAdapter; // reference to your adapter
if (adapter.indexOf(action) >= 0) {
adapter.notifyArrayItemRangeChanged(adapter.indexOf(action), 1);
return;
}
}
Well, I partially answered my own question.
If I know before the PlaybackControlsRow is created that I want to set it to the pause state (actually, playing state but showing pause button) then if I call setIndex(PlaypauseAction.PAUSE) on the PlayPauseAction before adding it to the controlsrow then it works.
It doesn't appear that I can modify it myself after adding it but that may be something else I'm doing wrong.

Show multiple lines in push notification android Phonegap

Im suffering from a problem in notification. Im doing my project in PHONEGAP.
I want to show multiple lines in push notification in android. Now i am only getting single line notification. i cannot expand or do anything with that notification. im using a phonegap plugin.
com.phonegap.plugins.PushPlugin
Please help me to overcome this problem.
Screen shot is given below.
Current Notification
Expected Notification
This involves a custom layout in the native notification (remoteviews) , so it is needed to modify you favorite plugin
Android custom notification layout with RemoteViews
In case of this plugin: https://github.com/phonegap-build/PushPlugin
Modify GCMIntentService.java, particulary NotificationCompat.Builder setContent with a the custom View. This custom view can be loaded from xml or instatiated by code: How to create a RelativeLayout programmatically with two buttons one on top of the other?
Example of a custom builder: Create custom notification, android
Change the params for the plugin or parse payload message to separate lines
Path: \platforms\android\src\com\plugin\gcm
Filename: GCMIntentService.java
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText(message);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));//add this line

How to create a custom control with MvvmCross Droid VideoView

I have a viewmodel for searching for videos which works great. I have added a play button and upon clicking I want to load a view that renders a VideoView. The search viewmodel contains enough data to generate the video's URL.
What is the best way to render the VideoView?
I've found this example but it appears to be an older version of MvvmCross:
https://gist.github.com/Alphapage/3945799
Should I create custom control like N=18 - Android Custom Controls - N+1 Days of MvvmCross?
http://www.youtube.com/watch?v=s1LhXdCTsn4&feature=youtube_gdata
If I create a custom control how should I pass the video's URL to the VideoView and start it playing?
I'm sure this is easy to do but I can't find a working example.
Thanks in advance
You could create a custom view as Stuart does, but rather than inheriting from View inherit from VideoView.
Then create a property called VideoUri, and when ever it's set call the SetVideoUri and start method on the base object. E.g.
Please note the following code was written in notepad, so may need some tweaking :)
public class BindableVideoView : VideoView
{
private Uri _videoUri = default(Uri);
public Uri VideoUri
{
get{ return _videoUri;}
set{
if(_videoUri!=value)
{
if(base.IsPlaying)
{
base.StopPlayback();
}
}
base.SetVideoURI(value);
base.Start();
}
}
}
You could do things like expose a property for IsPlaying and then your viewmodel could two-way bind to that so your viewmodel would know when you have finished playing the video

Categories

Resources