Skip to content

Commit

Permalink
Add preferred audio track language nova setting"
Browse files Browse the repository at this point in the history
  • Loading branch information
courville committed Jan 26, 2024
1 parent 394c0fd commit 0f6d81f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
4 changes: 3 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
<string name="get_subtitles_online">Get subtitles online</string>
<string name="toast_subloader_sub_found">Subtitles track found for this language</string>
<string name="toast_subloader_sub_not_found">Subtitles track not found for this language</string>
<string name="toast_subloader_service_unreachable">subtitles web service outage</string>
<string name="toast_subloader_service_unreachable">Subtitles web service outage</string>
<string name="menu_subloader_allfolder">Get missing subtitles</string>
<string name="dialog_subloader_copying">Copying subtitles…</string>
<string name="dialog_subloader_downloading">Downloading subtitles…</string>
Expand Down Expand Up @@ -602,6 +602,8 @@
<string name="summary_list_preference_primary">Select your languages for downloading subtitles</string>
<string name="favSubLang_title">Subtitles reading language</string>
<string name="favSubLang_summary">Choose your favorite language for reading subtitles</string>
<string name="favAudioLang_title">Audio preferred language</string>
<string name="favAudioLang_summary">Choose your favorite audio track language</string>
<string name="ui_mode_title">User interface mode</string>
<string name="ui_mode_summary">Choose between TV and Tablet/Phone UI</string>
<string name="preferences_video_about">About</string>
Expand Down
8 changes: 8 additions & 0 deletions res/xml/preferences_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@
android:summary="@string/preference_remove_dolby_vision_summary"
android:title="@string/preference_remove_dolby_vision"
app:iconSpaceReserved="false"/>
<ListPreference
android:dialogTitle="@string/favAudioLang_title"
android:entries="@array/entries_list_preference"
android:entryValues="@array/entryvalues_list_preference"
android:key="favAudioLang"
android:summary="@string/favAudioLang_summary"
android:title="@string/favAudioLang_title"
app:iconSpaceReserved="false"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="activate_tv_switch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
import static com.archos.filecorelibrary.FileUtils.hasManageExternalStoragePermission;
import static com.archos.filecorelibrary.FileUtils.stripExtensionFromName;
import static com.archos.mediacenter.utils.ISO639codes.findLanguageInString;
import static com.archos.mediacenter.utils.ISO639codes.isLanguageInString;
import static com.archos.mediacenter.utils.ISO639codes.replaceLanguageCodeInString;
import static com.archos.mediacenter.video.browser.subtitlesmanager.SubtitleManager.getLanguage3;
import static com.archos.mediacenter.video.utils.MiscUtils.isEmulator;
Expand Down Expand Up @@ -187,6 +188,7 @@ public class PlayerActivity extends AppCompatActivity implements PlayerControlle
private static final String KEY_NOTIFICATIONS_MODE = "notifications_mode";
private static final String KEY_NETWORK_BOOKMARKS = "network_bookmarks";
private static final String KEY_SUBTITLES_FAVORITE_LANGUAGE = "favSubLang";
private static final String KEY_AUDIO_TRACK_FAVORITE_LANGUAGE = "favAudioLang";
private static final String KEY_LOCK_ROTATION = "pref_lock_rotation";
private static final String KEY_HIDE_SUBTITLES = "subtitles_hide_default";
public static final String KEY_ADVANCED_VIDEO_ENABLED = "preferences_advanced_video_enabled";
Expand Down Expand Up @@ -385,6 +387,7 @@ public void handleMessage(Message msg) {
private boolean mPoster;
private String mPosterPath;

private boolean fileHasAlreadyPlayed = false;
private int mResume;
private long mVideoId;
private int mErrorCode = 0;
Expand All @@ -411,6 +414,7 @@ public void handleMessage(Message msg) {
private boolean mForceSWDecoding;
private boolean mHideSubtitles = false;
private String mSubsFavoriteLanguage;
private String mAudioTrackFavoriteLanguage;
private boolean mStopped;
private boolean mHdmiPlugged = false;
private boolean mLudoHmdiPlugged = false;
Expand Down Expand Up @@ -820,6 +824,7 @@ protected void onStart() {
mHideSubtitles = mPreferences.getBoolean(KEY_HIDE_SUBTITLES, false);
mNetworkBookmarksEnabled = mPreferences.getBoolean(KEY_NETWORK_BOOKMARKS, true);
mSubsFavoriteLanguage = mPreferences.getString(KEY_SUBTITLES_FAVORITE_LANGUAGE, Locale.getDefault().getISO3Language());
mAudioTrackFavoriteLanguage = mPreferences.getString(KEY_AUDIO_TRACK_FAVORITE_LANGUAGE, Locale.getDefault().getISO3Language());
mForceSWDecoding = mPreferences.getBoolean(KEY_FORCE_SW, false);
log.debug("onStart: setLockRotation " + mLockRotation);
setLockRotation(mLockRotation);
Expand Down Expand Up @@ -3558,7 +3563,7 @@ public void onAudioMetadataUpdated(VideoMetadata vMetadata, int newAudioTrack) {
boolean firstTimeUpdated = mAudioInfoController.getTrackCount() == 0;
int nbTrack = vMetadata.getAudioTrackNb();

log.info("onAudioMetadataUpdated: newAudio: " + newAudioTrack
log.debug("onAudioMetadataUpdated: newAudio: " + newAudioTrack
+ " mVideoInfo.audioTrack: " + mVideoInfo.audioTrack
+ " firstTimeUpdated: " + firstTimeUpdated
+ " nbTrack: " + nbTrack);
Expand All @@ -3571,8 +3576,20 @@ public void onAudioMetadataUpdated(VideoMetadata vMetadata, int newAudioTrack) {
mAudioInfoController.addTrack(name, summary);
}

// If no language set for subs, set the user favorite. Or system language if none.
log.debug("onAudioMetadataUpdated: fileHasAlreadyPlayed={}, mVideoInfo.audioTrack: {}", fileHasAlreadyPlayed, mVideoInfo.audioTrack);
if (! fileHasAlreadyPlayed) {
Locale locale = new Locale(mAudioTrackFavoriteLanguage);
for (int i = 0; i < nbTrack; ++i) { // loop through subtitleTracks to select default one not considering none
// select default locale and avoid forced subs
if (isLanguageInString(locale.getDisplayLanguage(), mAudioInfoController.getTrackNameAt(i).toString())) {
log.debug("onAudioMetadataUpdated: selected default track: #{} -> {} matching favorite audioTrack language {}", i, mAudioInfoController.getTrackNameAt(i).toString(), locale.getDisplayLanguage());
mVideoInfo.audioTrack = i;
break;
}
}
}
mAudioInfoController.setTrack(mVideoInfo.audioTrack);

}

public void onSubtitleMetadataUpdated(VideoMetadata vMetadata, int newSubtitleTrack) {
Expand Down Expand Up @@ -3699,7 +3716,12 @@ public void onAudioError(boolean isNotSupported,String msg) {
@Override
public void onVideoDb(final VideoDbInfo localVideoInfo, final VideoDbInfo remoteVideoInfo) {
log.debug("onVideoDb: localVideoInfo.subtitleTrack={}, remoteVideoInfo.subtitleTrack={}", ((localVideoInfo != null) ? localVideoInfo.subtitleTrack : "none"), ((remoteVideoInfo != null) ? remoteVideoInfo.subtitleTrack : "none"));
log.debug("onVideoDb: localVideoInfo.audioTrack={}, remoteVideoInfo.audioTrack={}", ((localVideoInfo != null) ? localVideoInfo.audioTrack : "none"), ((remoteVideoInfo != null) ? remoteVideoInfo.audioTrack : "none"));
log.debug("onVideoDb: trakt: " + localVideoInfo.traktResume+ " local "+ localVideoInfo.resume);
if (localVideoInfo.audioTrack == -1 && remoteVideoInfo.audioTrack == -1) {
log.debug("onVideoDb: first play");
fileHasAlreadyPlayed = false;
} else fileHasAlreadyPlayed = true;
if (localVideoInfo != null) {
final int localTraktPosition = Math.abs(localVideoInfo.duration>0 ? (int)(localVideoInfo.traktResume * (double) localVideoInfo.duration / 100) : 0);
log.info("onVideoDb: trakt calc: "+ localTraktPosition+ " local "+ localVideoInfo.resume);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,14 +1248,19 @@ public void onAudioMetadataUpdated(VideoMetadata vMetadata, int newAudioTrack) {
if (mVideoInfo == null) {
mNewAudioTrack = newAudioTrack;
mAudioSubtitleNeedUpdate = true;
log.debug("onAudioMetadataUpdated: mVideoInfo == null, mNewAudioTrack=" + mNewAudioTrack + " newAudioTrack=" + newAudioTrack + " mAudioSubtitleNeedUpdate=" + mAudioSubtitleNeedUpdate);
return;
} else {
log.debug("onAudioMetadataUpdated: mVideoInfo != null, mVideoInfo.audioTrack=" + mVideoInfo.audioTrack + " newAudioTrack=" + newAudioTrack + " mAudioSubtitleNeedUpdate=" + mAudioSubtitleNeedUpdate);
}
int nbTrack = vMetadata.getAudioTrackNb();
boolean supported = true;

if (mVideoInfo.audioTrack < 0 || mVideoInfo.audioTrack >= nbTrack
|| !vMetadata.getAudioTrack(mVideoInfo.audioTrack).supported) {
for (int i = 0; i < nbTrack; ++i) {
if (vMetadata.getAudioTrack(i).supported) {
log.debug("onAudioMetadataUpdated: selected first supported track #{} -> {}", i, vMetadata.getAudioTrack(i).name);
mVideoInfo.audioTrack = i;
supported = true;
break;
Expand All @@ -1275,7 +1280,6 @@ public void onAudioMetadataUpdated(VideoMetadata vMetadata, int newAudioTrack) {
if(mPlayerFrontend!=null) {
mPlayerFrontend.onAudioError(true, at != null ? at.format : "unknown");
}

}

if(mPlayerFrontend!=null) {
Expand Down Expand Up @@ -1317,6 +1321,7 @@ public void onSubtitleMetadataUpdated(VideoMetadata vMetadata, int newSubtitleTr
}
// mVideoInfo.subtitleTrack is the track number without the none track 0<=mVideoInfo.subtitleTrack<nbTrack
if (mVideoInfo.subtitleTrack >= 0 && mVideoInfo.subtitleTrack < nbTrack) {
log.debug("onSubtitleMetadataUpdated: newSubtitleTrack={}, mVideoInfo.subtitleTrack={}", newSubtitleTrack, mVideoInfo.subtitleTrack);
if (newSubtitleTrack != mVideoInfo.subtitleTrack &&
!mPlayer.setSubtitleTrack(mVideoInfo.subtitleTrack))
mVideoInfo.subtitleTrack = noneTrack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public class VideoPreferencesCommon implements OnSharedPreferenceChangeListener
public static final String KEY_AUDIO_INTERFACE_CHOICE = "audio_interface_choice";
public static final String KEY_SUBTITLES_HIDE = "subtitles_hide_default";
public static final String KEY_SUBTITLES_FAV_LANG = "favSubLang";
public static final String KEY_AUDIO_TRACK_FAV_LANG = "favAudioLang";
public static final String KEY_TRAKT_CATEGORY = "trakt_category";
public static final String KEY_TRAKT_GETFULL = "trakt_getfull";
public static final String KEY_TRAKT_SIGNIN = "trakt_signin";
Expand Down Expand Up @@ -220,6 +221,7 @@ public class VideoPreferencesCommon implements OnSharedPreferenceChangeListener
private PreferenceCategory mScraperCategory = null;
private ListPreference mSubtitlesFavLangPreferences = null;
private MultiSelectListPreference mSubtitlesDownloadLanguagePreferences = null;
private ListPreference mAudioTrackFavoriteLanguage = null;
private CheckBoxPreference mEnableSponsor = null;
private CheckBoxPreference mWatchingUpNext = null;
private PreferenceCategory mAboutPreferences = null;
Expand Down Expand Up @@ -263,6 +265,7 @@ public class VideoPreferencesCommon implements OnSharedPreferenceChangeListener
CharSequence[] languageListNewEntries;
CharSequence[] languageListNewEntryValues;
int systemLanguageIndex;
int systemAudioLanguageIndex;

public VideoPreferencesCommon(PreferenceFragmentCompat preferencesFragment) {
mPreferencesFragment = preferencesFragment;
Expand Down Expand Up @@ -699,6 +702,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
mSubtitlesFavLangPreferences.setEntryValues(languageListNewEntryValues);
if(systemLanguageIndex>=0) mSubtitlesFavLangPreferences.setValueIndex(systemLanguageIndex);

mAudioTrackFavoriteLanguage = (ListPreference) findPreference(KEY_AUDIO_TRACK_FAV_LANG);
mAudioTrackFavoriteLanguage.setEntries(languageListNewEntries);
mAudioTrackFavoriteLanguage.setEntryValues(languageListNewEntryValues);
if(systemLanguageIndex>=0) mAudioTrackFavoriteLanguage.setValueIndex(systemAudioLanguageIndex);

ListPreference lp = (ListPreference) findPreference("codepage");
int cp = MediaFactory.getCodepage();
int cpStringID = getResources().getIdentifier("codepage_extra_" + cp, "string", getActivity().getPackageName());
Expand Down Expand Up @@ -1015,16 +1023,23 @@ private void buildLanguageList() {
languageListEntryValues.toArray(languageListNewEntryValues);
systemLanguageIndex = -1;
final String currentFavoriteLang;
final String currentAudioFavoriteLang;
if (CustomApplication.useOpenSubtitlesRestApi())
currentFavoriteLang = getPreferenceManager().getSharedPreferences().getString(KEY_SUBTITLES_FAV_LANG, Locale.getDefault().getLanguage());
else
currentFavoriteLang = getPreferenceManager().getSharedPreferences().getString(KEY_SUBTITLES_FAV_LANG, Locale.getDefault().getISO3Language());
log.debug("onCreatePreferences: currentFavoriteLang={}", currentFavoriteLang);

currentAudioFavoriteLang = getPreferenceManager().getSharedPreferences().getString(KEY_AUDIO_TRACK_FAV_LANG, Locale.getDefault().getLanguage());

log.debug("onCreatePreferences: currentSubFavoriteLang={}, currentAudioFavoriteLang={}", currentFavoriteLang, currentAudioFavoriteLang);
int i = 0;
for(CharSequence value : languageListNewEntryValues){
if(value.toString().equalsIgnoreCase(currentFavoriteLang)) {
systemLanguageIndex = i;
}
if(value.toString().equalsIgnoreCase(currentAudioFavoriteLang)) {
systemAudioLanguageIndex = i;
}
i++;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/noamazon/play/release-notes/en-US/internal.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Add preferred audio language option for multi audio track videos
- Another attempt to fix ftp
- libyuv upstep aligned on chromium master
- Stability enhancements

0 comments on commit 0f6d81f

Please sign in to comment.