feat: allow playing multiple media (#755)

* feat: allow playing multiple media

* replace audio overlay icon

---------

Co-authored-by: sk <sk22@mailbox.org>
This commit is contained in:
FineFindus
2023-08-05 20:35:57 +02:00
committed by GitHub
parent fe2039062b
commit 584b11fce3
7 changed files with 24 additions and 3 deletions

View File

@@ -169,7 +169,8 @@ public class AudioPlayerService extends Service{
}
updateNotification(false, false);
getSystemService(AudioManager.class).requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
int audiofocus = GlobalUserPreferences.overlayMedia ? AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK : AudioManager.AUDIOFOCUS_GAIN;
getSystemService(AudioManager.class).requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, audiofocus);
player=new MediaPlayer();
player.setOnPreparedListener(this::onPlayerPrepared);

View File

@@ -59,6 +59,7 @@ public class GlobalUserPreferences{
public static boolean disableM3PillActiveIndicator;
public static boolean showNavigationLabels;
public static boolean displayPronounsInTimelines, displayPronounsInThreads, displayPronounsInUserListings;
public static boolean overlayMedia;
private static SharedPreferences getPrefs(){
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
@@ -117,6 +118,7 @@ public class GlobalUserPreferences{
displayPronounsInTimelines=prefs.getBoolean("displayPronounsInTimelines", true);
displayPronounsInThreads=prefs.getBoolean("displayPronounsInThreads", true);
displayPronounsInUserListings=prefs.getBoolean("displayPronounsInUserListings", true);
overlayMedia=prefs.getBoolean("overlayMedia", false);
if (prefs.contains("prefixRepliesWithRe")) {
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
@@ -174,6 +176,7 @@ public class GlobalUserPreferences{
.putBoolean("displayPronounsInTimelines", displayPronounsInTimelines)
.putBoolean("displayPronounsInThreads", displayPronounsInThreads)
.putBoolean("displayPronounsInUserListings", displayPronounsInUserListings)
.putBoolean("overlayMedia", overlayMedia)
.apply();
}

View File

@@ -30,7 +30,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment<Void> impleme
// MEGALODON
private MastodonLanguage.LanguageResolver languageResolver;
private ListItem<Void> prefixRepliesItem, replyVisibilityItem;
private CheckableListItem<Void> forwardReportsItem, remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem;
private CheckableListItem<Void> forwardReportsItem, remoteLoadingItem, showBoostsItem, showRepliesItem, loadNewPostsItem, seeNewPostsBtnItem, overlayMediaItem;
@Override
public void onCreate(Bundle savedInstanceState){
@@ -47,6 +47,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment<Void> impleme
languageItem=new ListItem<>(getString(R.string.default_post_language), postLanguage!=null ? postLanguage.getDisplayName(getContext()) : null, R.drawable.ic_fluent_local_language_24_regular, this::onDefaultLanguageClick),
altTextItem=new CheckableListItem<>(R.string.settings_alt_text_reminders, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.altTextReminders, R.drawable.ic_fluent_image_alt_text_24_regular, ()->toggleCheckableItem(altTextItem)),
playGifsItem=new CheckableListItem<>(R.string.settings_gif, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.playGifs, R.drawable.ic_fluent_gif_24_regular, ()->toggleCheckableItem(playGifsItem)),
overlayMediaItem=new CheckableListItem<>(R.string.sk_settings_continues_playback, R.string.sk_settings_continues_playback_summary, CheckableListItem.Style.SWITCH, GlobalUserPreferences.overlayMedia, R.drawable.ic_fluent_play_circle_hint_24_regular, ()->toggleCheckableItem(overlayMediaItem)),
customTabsItem=new CheckableListItem<>(R.string.settings_custom_tabs, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.useCustomTabs, R.drawable.ic_fluent_link_24_regular, ()->toggleCheckableItem(customTabsItem)),
confirmUnfollowItem=new CheckableListItem<>(R.string.settings_confirm_unfollow, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmUnfollow, R.drawable.ic_fluent_person_delete_24_regular, ()->toggleCheckableItem(confirmUnfollowItem)),
confirmBoostItem=new CheckableListItem<>(R.string.settings_confirm_boost, 0, CheckableListItem.Style.SWITCH, GlobalUserPreferences.confirmBoost, R.drawable.ic_fluent_arrow_repeat_all_24_regular, ()->toggleCheckableItem(confirmBoostItem)),
@@ -162,6 +163,7 @@ public class SettingsBehaviorFragment extends BaseSettingsFragment<Void> impleme
protected void onHidden(){
super.onHidden();
GlobalUserPreferences.playGifs=playGifsItem.checked;
GlobalUserPreferences.overlayMedia=overlayMediaItem.checked;
GlobalUserPreferences.useCustomTabs=customTabsItem.checked;
GlobalUserPreferences.altTextReminders=altTextItem.checked;
GlobalUserPreferences.confirmUnfollow=customTabsItem.checked;

View File

@@ -3,6 +3,7 @@ package org.joinmastodon.android.model;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadataRetriever;
import com.google.gson.annotations.SerializedName;
@@ -77,6 +78,13 @@ public class Attachment extends BaseModel{
return 0;
}
public boolean hasSound() {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(url);
String hasAudioStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_AUDIO);
return "yes".equals(hasAudioStr);
}
@Override
public void postprocess() throws ObjectValidationException{
super.postprocess();

View File

@@ -45,6 +45,7 @@ import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.MastodonAPIController;
import org.joinmastodon.android.model.Attachment;
@@ -418,7 +419,8 @@ public class PhotoViewer implements ZoomPanView.Listener{
WindowManager.LayoutParams wlp=(WindowManager.LayoutParams) windowView.getLayoutParams();
wlp.flags|=WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
wm.updateViewLayout(windowView, wlp);
activity.getSystemService(AudioManager.class).requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
int audiofocus = GlobalUserPreferences.overlayMedia ? AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK : AudioManager.AUDIOFOCUS_GAIN;
activity.getSystemService(AudioManager.class).requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, audiofocus);
}
screenOnRefCount++;
}

View File

@@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M12 2c-0.667 0-1.32 0.065-1.95 0.19-0.407 0.08-0.671 0.475-0.591 0.882 0.08 0.406 0.475 0.67 0.881 0.59C10.877 3.556 11.431 3.5 12 3.5s1.123 0.056 1.66 0.162c0.406 0.08 0.8-0.184 0.881-0.59 0.08-0.407-0.184-0.801-0.59-0.882C13.319 2.065 12.667 2 12 2zM7.278 4.931c0.344-0.23 0.436-0.696 0.206-1.04-0.23-0.344-0.697-0.437-1.04-0.206-1.09 0.73-2.03 1.668-2.76 2.758-0.23 0.345-0.137 0.81 0.207 1.04 0.344 0.231 0.81 0.139 1.04-0.205 0.621-0.927 1.42-1.726 2.347-2.347zm10.279-1.246c-0.345-0.23-0.81-0.138-1.04 0.206-0.231 0.344-0.139 0.81 0.205 1.04 0.927 0.621 1.726 1.42 2.347 2.347 0.23 0.344 0.696 0.436 1.04 0.206 0.344-0.23 0.437-0.697 0.206-1.04-0.73-1.09-1.668-2.03-2.758-2.76zm4.253 6.364c-0.08-0.406-0.475-0.67-0.882-0.59-0.406 0.08-0.67 0.475-0.59 0.881 0.106 0.537 0.162 1.091 0.162 1.66s-0.056 1.123-0.162 1.66c-0.08 0.406 0.184 0.8 0.59 0.881 0.407 0.08 0.801-0.184 0.882-0.59C21.935 13.319 22 12.667 22 12s-0.065-1.32-0.19-1.95zM3.662 10.34c0.08-0.406-0.184-0.8-0.59-0.881-0.407-0.08-0.801 0.184-0.882 0.59C2.065 10.681 2 11.333 2 12s0.065 1.32 0.19 1.95c0.08 0.407 0.475 0.671 0.882 0.591 0.406-0.08 0.67-0.475 0.59-0.881C3.556 13.123 3.5 12.569 3.5 12s0.056-1.123 0.162-1.66zm1.27 6.382C4.7 16.378 4.234 16.286 3.89 16.516s-0.437 0.697-0.206 1.04c0.73 1.09 1.668 2.03 2.758 2.76 0.345 0.23 0.81 0.137 1.04-0.207 0.231-0.344 0.139-0.81-0.205-1.04-0.927-0.621-1.726-1.42-2.347-2.347zm15.383 0.835c0.23-0.345 0.138-0.81-0.206-1.04-0.344-0.231-0.81-0.139-1.04 0.205-0.621 0.927-1.42 1.726-2.347 2.347-0.344 0.23-0.436 0.696-0.206 1.04 0.23 0.344 0.697 0.437 1.04 0.206 1.09-0.73 2.03-1.668 2.76-2.758zm-9.975 2.781c-0.406-0.08-0.8 0.184-0.881 0.59-0.08 0.407 0.184 0.801 0.59 0.882C10.681 21.935 11.333 22 12 22s1.32-0.065 1.95-0.19c0.407-0.08 0.671-0.475 0.591-0.882-0.08-0.406-0.475-0.67-0.881-0.59C13.123 20.444 12.569 20.5 12 20.5s-1.123-0.056-1.66-0.162zM9 9.248c0-0.952 1.023-1.554 1.856-1.093l5.757 3.186C16.852 11.473 17 11.724 17 11.997c0 0.272-0.148 0.523-0.387 0.655l-5.757 3.187C10.023 16.299 9 15.697 9 14.745V9.247z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@@ -16,6 +16,8 @@
<string name="sk_image_description">Image description</string>
<string name="sk_visibility_unlisted">Unlisted</string>
<string name="sk_settings_show_replies">Show replies</string>
<string name="sk_settings_continues_playback">Audio overlay</string>
<string name="sk_settings_continues_playback_summary">Allow already playing media to continue playing, overlaying the new playback</string>
<string name="sk_quoting_user">Quoting %s</string>
<string name="sk_settings_reply_visibility">Reply visibility</string>
<string name="sk_settings_reply_visibility_all">All replies</string>