Skip to content

Commit

Permalink
Use ExoPlayer for audio/video player
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed May 11, 2021
1 parent 02d0f8a commit 286375b
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 266 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ dependencies {
ktlint "com.pinterest:ktlint:0.41.0"
implementation 'org.conscrypt:conscrypt-android:2.5.1'

implementation 'com.google.android.exoplayer:exoplayer:2.13.2'

// Shimmer animation
implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'

Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/lint-results.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 232 warnings</span>
<span class="mdl-layout-title">Lint Report: 231 warnings</span>
2 changes: 1 addition & 1 deletion src/main/java/com/nextcloud/client/media/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class Player(
private var enqueuedFile: PlaylistItem? = null

private var playedFile: OCFile? = null
private var startPositionMs: Int = 0
private var startPositionMs: Long = 0
private var autoPlay = true
private var user: User? = null
private var dataSource: String? = null
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nextcloud/client/media/PlayerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class PlayerService : Service() {
private fun onActionPlay(intent: Intent) {
val user: User = intent.getParcelableExtra(EXTRA_USER) as User
val file: OCFile = intent.getParcelableExtra(EXTRA_FILE) as OCFile
val startPos = intent.getIntExtra(EXTRA_START_POSITION_MS, 0)
val startPos = intent.getLongExtra(EXTRA_START_POSITION_MS, 0)
val autoPlay = intent.getBooleanExtra(EXTRA_AUTO_PLAY, true)
val item = PlaylistItem(file = file, startPositionMs = startPos, autoPlay = autoPlay, user = user)
player.play(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PlayerServiceConnection(private val context: Context) : MediaController.Me
}
}

fun start(user: User, file: OCFile, playImmediately: Boolean, position: Int) {
fun start(user: User, file: OCFile, playImmediately: Boolean, position: Long) {
val i = Intent(context, PlayerService::class.java)
i.putExtra(PlayerService.EXTRA_USER, user)
i.putExtra(PlayerService.EXTRA_FILE, file)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nextcloud/client/media/PlaylistItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.nextcloud.client.media
import com.nextcloud.client.account.User
import com.owncloud.android.datamodel.OCFile

data class PlaylistItem(val file: OCFile, val startPositionMs: Int, val autoPlay: Boolean, val user: User)
data class PlaylistItem(val file: OCFile, val startPositionMs: Long, val autoPlay: Boolean, val user: User)
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
import org.parceler.Parcels;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -559,7 +558,7 @@ private Fragment chooseInitialSecondFragment(OCFile file, User user) {
Fragment secondFragment = null;
if (file != null && !file.isFolder()) {
if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) {
int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
long startPlaybackPosition = getIntent().getLongExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
secondFragment = PreviewMediaFragment.newInstance(file, user, startPlaybackPosition, autoplay);
} else if (file.isDown() && PreviewTextFileFragment.canBePreviewed(file)) {
Expand Down Expand Up @@ -845,7 +844,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
second != null && second.getFile() != null ||
isSearchOpen()) {
onBackPressed();
} else if (getLeftFragment() instanceof FileDetailFragment) {
} else if (getLeftFragment() instanceof FileDetailFragment ||
getLeftFragment() instanceof PreviewMediaFragment) {
onBackPressed();
} else {
openDrawer();
Expand Down Expand Up @@ -1898,7 +1898,7 @@ private void onRenameFileOperationFinish(RenameFileOperation operation,
renamedFile.equals(details.getFile())) {
((PreviewMediaFragment) details).updateFile(renamedFile);
if (PreviewMediaFragment.canBePreviewed(renamedFile)) {
int position = ((PreviewMediaFragment) details).getPosition();
long position = ((PreviewMediaFragment) details).getPosition();
startMediaPreview(renamedFile, position, true, true, true);
} else {
getFileOperationsHelper().openFile(renamedFile);
Expand Down Expand Up @@ -2182,12 +2182,13 @@ public void startImagePreview(OCFile file, VirtualFolderType type, boolean showP
* Stars the preview of an already down media {@link OCFile}.
*
* @param file Media {@link OCFile} to preview.
* @param startPlaybackPosition Media position where the playback will be started,
* in milliseconds.
* @param autoplay When 'true', the playback will start without user
* interactions.
* @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
* @param autoplay When 'true', the playback will start without user interactions.
*/
public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay, boolean showPreview,
public void startMediaPreview(OCFile file,
long startPlaybackPosition,
boolean autoplay,
boolean showPreview,
boolean streamMedia) {
Optional<User> user = getUser();
if (!user.isPresent()) {
Expand Down Expand Up @@ -2362,7 +2363,7 @@ public void onMessageEvent(SyncEventFinished event) {
startTextPreview((OCFile) bundle.get(EXTRA_FILE), true);
} else if (bundle.containsKey(PreviewVideoActivity.EXTRA_START_POSITION)) {
startMediaPreview((OCFile) bundle.get(EXTRA_FILE),
(int) bundle.get(PreviewVideoActivity.EXTRA_START_POSITION),
(long) bundle.get(PreviewVideoActivity.EXTRA_START_POSITION),
(boolean) bundle.get(PreviewVideoActivity.EXTRA_AUTOPLAY), true, true);
} else if (bundle.containsKey(PreviewImageActivity.EXTRA_VIRTUAL_TYPE)) {
startImagePreview((OCFile)bundle.get(EXTRA_FILE),
Expand Down
Loading

0 comments on commit 286375b

Please sign in to comment.