Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature play with button #571

Merged
merged 9 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
* Include system logs in crash reports
*/
var acraIncludeSystemLogs = Preference.boolean(ACRA.PREF_ENABLE_SYSTEM_LOGS, true)

/**
* chosen player for play with button - changes every time user chooses a player with "play with" button
*/

var chosenPlayer = Preference.enum("chosen_player",PreferredVideoPlayer.VLC)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use SystemPreferences

}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ enum class PreferredVideoPlayer {
* Use external player
*/
@EnumDisplayOptions(R.string.pref_video_player_external)
EXTERNAL
EXTERNAL,

/**
* Choose a player - play with button
*/
@EnumDisplayOptions(R.string.pref_video_player_choose)
CHOOSE
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;

import androidx.leanback.app.BackgroundManager;
import androidx.leanback.app.RowsSupportFragment;
Expand All @@ -40,9 +41,12 @@
import org.jellyfin.androidtv.data.querying.StdItemQuery;
import org.jellyfin.androidtv.data.querying.TrailersQuery;
import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer;
import org.jellyfin.androidtv.ui.IRecordingIndicatorView;
import org.jellyfin.androidtv.ui.RecordPopup;
import org.jellyfin.androidtv.ui.TextUnderButton;
import org.jellyfin.androidtv.ui.playback.ExternalPlayerActivity;
import org.jellyfin.androidtv.ui.playback.PlaybackController;
import org.jellyfin.androidtv.ui.shared.BaseActivity;
import org.jellyfin.androidtv.ui.shared.IMessageListener;
import org.jellyfin.androidtv.ui.itemhandling.BaseRowItem;
Expand Down Expand Up @@ -140,7 +144,7 @@ public class FullDetailsActivity extends BaseActivity implements IRecordingIndic

private Lazy<ApiClient> apiClient = inject(ApiClient.class);
private Lazy<GsonJsonSerializer> serializer = inject(GsonJsonSerializer.class);

private Lazy<UserPreferences> userPreferences = inject(UserPreferences.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -839,6 +843,7 @@ public void onClick(DialogInterface dialog, int which) {
private TextUnderButton queueButton = null;
private TextUnderButton deleteButton = null;
private TextUnderButton moreButton;
private TextUnderButton playWithButton = null;

private void addButtons(int buttonSize) {
String buttonLabel;
Expand Down Expand Up @@ -888,18 +893,25 @@ public void onError(Exception exception) {
mDetailsOverviewRow.addAction(mResumeButton);
boolean resumeButtonVisible = (mBaseItem.getBaseItemType() == BaseItemType.Series && !mBaseItem.getUserData().getPlayed()) || (mBaseItem.getCanResume());
mResumeButton.setVisibility(resumeButtonVisible ? View.VISIBLE : View.GONE);

TextUnderButton play = new TextUnderButton(this, R.drawable.ic_play, buttonSize, 2, getString(BaseItemUtils.isLiveTv(mBaseItem) ? R.string.lbl_tune_to_channel : mBaseItem.getIsFolderItem() ? R.string.lbl_play_all : R.string.lbl_play), new View.OnClickListener() {
@Override
public void onClick(View v) {
play(mBaseItem, 0, false);
}
});
mDetailsOverviewRow.addAction(play);
boolean isPlayerPrefChoose = userPreferences.getValue().get(UserPreferences.Companion.getVideoPlayer()) == PreferredVideoPlayer.CHOOSE;
TextUnderButton play = null;
if (!isPlayerPrefChoose) {
play = new TextUnderButton(this, R.drawable.ic_play, buttonSize, 2, getString(BaseItemUtils.isLiveTv(mBaseItem) ? R.string.lbl_tune_to_channel : mBaseItem.getIsFolderItem() ? R.string.lbl_play_all : R.string.lbl_play), new View.OnClickListener() {
@Override
public void onClick(View v) {
play(mBaseItem, 0, false);
}
});
mDetailsOverviewRow.addAction(play);
}

if (resumeButtonVisible) {
mResumeButton.requestFocus();
} else {
play.requestFocus();
if (!isPlayerPrefChoose) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use else if

play.requestFocus();
}

}

if (!mBaseItem.getIsFolderItem() && !BaseItemUtils.isLiveTv(mBaseItem)) {
Expand Down Expand Up @@ -935,6 +947,8 @@ public void onClick(View v) {

}



if (mBaseItem.getLocalTrailerCount() != null && mBaseItem.getLocalTrailerCount() > 0) {
TextUnderButton trailer = new TextUnderButton(this, R.drawable.ic_trailer, buttonSize, getString(R.string.lbl_play_trailers), new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -1136,6 +1150,8 @@ public void onClick(View v) {

mDetailsOverviewRow.addAction(mPrevButton);



//now go get our prev episode id
EpisodeQuery adjacent = new EpisodeQuery();
adjacent.setUserId(TvApp.getApplication().getCurrentUser().getId());
Expand Down Expand Up @@ -1260,6 +1276,18 @@ public void onClick(View v) {
more.show();
}
});
if (userPreferences.getValue().get(UserPreferences.Companion.getVideoPlayer()) == PreferredVideoPlayer.CHOOSE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably easier to add an else statement when checking if the play button should be shown

playWithButton = new TextUnderButton(this, R.drawable.ic_add, buttonSize, 3, getString(R.string.play_with), new View.OnClickListener() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since either the play or play with button is shown you can probably reuse the playButton property

@Override
public void onClick(View view) {
PopupMenu more = new PopupMenu(mActivity, view);
more.inflate(R.menu.menu_details_play_with);
more.setOnMenuItemClickListener(playWithMenuListener);
more.show();
}
});
mDetailsOverviewRow.addAction(playWithButton);
}

moreButton.setVisibility(View.GONE);
mDetailsOverviewRow.addAction(moreButton);
Expand Down Expand Up @@ -1325,6 +1353,42 @@ public boolean onMenuItemClick(MenuItem item) {
return false;
}
};
PlaybackController playbackController= new PlaybackController(MediaManager.getCurrentVideoQueue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unused


PopupMenu.OnMenuItemClickListener playWithMenuListener = new PopupMenu.OnMenuItemClickListener() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark private

@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {

case R.id.play_with_vlc:
userPreferences.getValue().set(UserPreferences.Companion.getChosenPlayer(),PreferredVideoPlayer.VLC);
play(mBaseItem, 0, false);
return true;
case R.id.play_with_exo:
userPreferences.getValue().set(UserPreferences.Companion.getChosenPlayer(),PreferredVideoPlayer.EXOPLAYER);
play(mBaseItem, 0, false);
return true;
case R.id.play_with_external:
userPreferences.getValue().set(UserPreferences.Companion.getChosenPlayer(),PreferredVideoPlayer.EXTERNAL);
PlaybackHelper.getItemsToPlay(mBaseItem, false , false, new Response<List<BaseItemDto>>() {
@Override
public void onResponse(List<BaseItemDto> response) {
if (mBaseItem.getBaseItemType() == BaseItemType.MusicArtist) {
MediaManager.playNow(response);
} else {
Intent intent = new Intent(FullDetailsActivity.this, ExternalPlayerActivity.class);
MediaManager.setCurrentVideoQueue(response);
intent.putExtra("Position", 0);
startActivity(intent);
}
}
});
return true;

}
return false;
}
};

RecordPopup mRecordPopup;
public void showRecordingOptions(String id, final BaseItemDto program, final boolean recordSeries) {
Expand Down Expand Up @@ -1472,14 +1536,14 @@ public void onResponse(UserItemDataDto response) {
}

protected void play(final BaseItemDto item, final int pos, final boolean shuffle) {
final Activity activity = this;

PlaybackHelper.getItemsToPlay(item, pos == 0 && item.getBaseItemType() == BaseItemType.Movie, shuffle, new Response<List<BaseItemDto>>() {
@Override
public void onResponse(List<BaseItemDto> response) {
if (item.getBaseItemType() == BaseItemType.MusicArtist) {
MediaManager.playNow(response);
} else {
Intent intent = new Intent(activity, mApplication.getPlaybackActivityClass(item.getBaseItemType()));
Intent intent = new Intent(FullDetailsActivity.this, mApplication.getPlaybackActivityClass(item.getBaseItemType()));
MediaManager.setCurrentVideoQueue(response);
intent.putExtra("Position", pos);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ public PlaybackController(List<BaseItemDto> items, IPlaybackOverlayFragment frag
useVlc = userPreferences.getValue().get(UserPreferences.Companion.getVideoPlayer()) == PreferredVideoPlayer.VLC;
}

public PlaybackController(List<BaseItemDto> items) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is unused too

mItems = items;
mApplication = TvApp.getApplication();
mHandler = new Handler();

refreshRateSwitchingEnabled = DeviceUtils.is60() && userPreferences.getValue().get(UserPreferences.Companion.getRefreshRateSwitchingEnabled());
if (refreshRateSwitchingEnabled) getDisplayModes();

// Set default value for useVlc field
// when set to auto the default will be exoplayer
useVlc = userPreferences.getValue().get(UserPreferences.Companion.getVideoPlayer()) == PreferredVideoPlayer.VLC;
}

public void init(VideoManager mgr) {
mVideoManager = mgr;
directStreamLiveTv = userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled());
Expand Down Expand Up @@ -478,6 +491,16 @@ public void onResponse(StreamInfo internalResponse) {
!internalResponse.getMediaSource().getDefaultAudioStream().getCodec().equals("dts"))) &&
(!DeviceUtils.isFireTvStick() ||
(vlcResponse.getMediaSource().getVideoStream() != null && vlcResponse.getMediaSource().getVideoStream().getWidth() < 1000));
} else if (preferredVideoPlayer == PreferredVideoPlayer.CHOOSE) {
PreferredVideoPlayer preferredVideoPlayerByPlayWith = userPreferences.getValue().get(UserPreferences.Companion.getChosenPlayer());
if (preferredVideoPlayerByPlayWith == PreferredVideoPlayer.VLC) {
useVlc = true;
} else if (preferredVideoPlayerByPlayWith == PreferredVideoPlayer.EXOPLAYER) {
// Make sure to not use VLC
useVlc = false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (preferredVideoPlayerByPlayWith == PreferredVideoPlayer.VLC) {
useVlc = true;
} else if (preferredVideoPlayerByPlayWith == PreferredVideoPlayer.EXOPLAYER) {
// Make sure to not use VLC
useVlc = false;
}
useVlc = preferredVideoPlayerByPlayWith == PreferredVideoPlayer.VLC;


System.out.println("PREFERRED PLAYER " + preferredVideoPlayerByPlayWith.name());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Timber for logging

}

Timber.i(useVlc ? "Preferring VLC" : "Will use internal player");
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/menu/menu_details_play_with.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="@string/play_with_vlc"
android:id="@+id/play_with_vlc"
android:icon="@drawable/ic_heart"
/>

<item android:title="@string/play_with_exo_player"
android:id="@+id/play_with_exo"
android:icon="@drawable/ic_heart"
/>
<item android:title="@string/play_with_external_app"
android:id="@+id/play_with_external"
android:icon="@drawable/ic_heart"
/>
</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
<string name="pref_video_player_exoplayer">ExoPlayer</string>
<string name="pref_video_player_vlc">libVLC</string>
<string name="pref_video_player_external">External app</string>
<string name="pref_video_player_choose">Always ask</string>
<string name="pref_about_title">About</string>
<string name="pref_media_player">Preferred media player</string>
<string name="pref_next_up_timeout_summary">How long to wait before playing the next item</string>
Expand Down Expand Up @@ -403,4 +404,8 @@
<string name="not_deleted">Item NOT Deleted</string>
<string name="turn_off">Turn this option off</string>
<string name="just_one">Just this one</string>
<string name="play_with_vlc">Play with Vlc</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="play_with_vlc">Play with Vlc</string>
<string name="play_with_vlc">Play with libVLC</string>

<string name="play_with_exo_player">Play with Exo Player</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="play_with_exo_player">Play with Exo Player</string>
<string name="play_with_exo_player">Play with ExoPlayer</string>

<string name="play_with_external_app">Play with External App</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<string name="play_with_external_app">Play with External App</string>
<string name="play_with_external_app">Play with external app</string>

<string name="play_with">Play with</string>
</resources>