Skip to content

Commit

Permalink
optimize podcast playback / fix seek / fix rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Development committed Mar 27, 2022
1 parent 9856005 commit e41e159
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import androidx.appcompat.app.AlertDialog;

import android.os.Handler;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
Expand Down Expand Up @@ -44,6 +43,7 @@
import de.luhmer.owncloudnewsreader.ListView.PodcastFeedArrayAdapter;
import de.luhmer.owncloudnewsreader.databinding.FragmentPodcastBinding;
import de.luhmer.owncloudnewsreader.events.podcast.CollapsePodcastView;
import de.luhmer.owncloudnewsreader.events.podcast.ExitPlayback;
import de.luhmer.owncloudnewsreader.events.podcast.ExpandPodcastView;
import de.luhmer.owncloudnewsreader.events.podcast.SpeedPodcast;
import de.luhmer.owncloudnewsreader.events.podcast.StartDownloadPodcast;
Expand Down Expand Up @@ -229,6 +229,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
binding.btnPreviousPodcastSlider.setOnClickListener((v) -> windBack());
binding.btnPodcastSpeed.setOnClickListener((v) -> openSpeedMenu());

binding.btnExitPodcast.setOnClickListener((v) -> eventBus.post(new ExitPlayback()));

//View view = inflater.inflate(R.layout.fragment_podcast, container, false);

if(getActivity() instanceof PodcastFragmentActivity) {
Expand Down Expand Up @@ -301,15 +303,16 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.v(TAG, "onStartTrackingTouch");
before = seekBar.getProgress();
blockSeekbarUpdate = true;
}

@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
Log.v(TAG, "onStopTrackingTouch");
int diffInSeconds = seekBar.getProgress() - before;
eventBus.post(new WindPodcast(diffInSeconds));
int after = seekBar.getProgress();
long ms = Math.round((after / 100d) * maxPositionInMillis);
Log.v(TAG, "onStopTrackingTouch - after (%): " + after + " - ms: " + ms);

eventBus.post(new WindPodcast(ms));
blockSeekbarUpdate = false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.media.session.MediaControllerCompat;
import android.util.Log;
import android.util.TypedValue;
Expand All @@ -34,6 +35,7 @@
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.di.ApiProvider;
import de.luhmer.owncloudnewsreader.events.podcast.CollapsePodcastView;
import de.luhmer.owncloudnewsreader.events.podcast.ExitPlayback;
import de.luhmer.owncloudnewsreader.events.podcast.ExpandPodcastView;
import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
Expand Down Expand Up @@ -205,17 +207,10 @@ protected void updatePodcastView() {
if(mPodcastFragment == null) {
mPodcastFragment = PodcastFragment.newInstance();
}
/*
if(mPodcastFragment != null) {
getSupportFragmentManager().beginTransaction().remove(mPodcastFragment).commitAllowingStateLoss();
}
*/

getSupportFragmentManager().beginTransaction()
.replace(R.id.podcast_frame, mPodcastFragment)
.commitAllowingStateLoss();

collapsePodcastView();
// collapsePodcastView();
}


Expand All @@ -231,6 +226,12 @@ public void onEvent(ExpandPodcastView event) {
expandPodcastView();
}

@Subscribe
public void onEvent(ExitPlayback event) {
Log.v(TAG, "onEvent(ExitPlayback) called with: event = [" + event + "]");
collapsePodcastView();
getPodcastSlidingUpPanelLayout().setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}

private void collapsePodcastView() {
getPodcastSlidingUpPanelLayout().setPanelHeight(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.luhmer.owncloudnewsreader.events.podcast;

public class ExitPlayback {
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static long getMaxIdFromItems(List<RssItem> buffer) {
}

public static boolean performDatabaseBatchInsert(DatabaseConnectionOrm dbConn, List<RssItem> buffer) {
Log.v(TAG, "performDatabaseBatchInsert() called with: dbConn = [" + dbConn + "], buffer = [" + buffer + "]");
Log.v(TAG, "performDatabaseBatchInsert() called with [" + buffer.size() + " rss items]");
dbConn.insertNewItems(buffer);
buffer.clear();
return true;
Expand Down Expand Up @@ -183,13 +183,16 @@ public void onSubscribe(@NonNull Disposable d) {
@Override
public void onNext(@NonNull RssItem rssItem) {
long rssLastModified = rssItem.getLastModified().getTime();
// Log.v(TAG, "onNext() rssItem: " + rssItem.getTitle() + " - " + rssItem.getLastModified());

// If updated item is unread and last modification was different from last sync time
if (!rssItem.getRead() && rssLastModified != lastModified) {
totalUpdatedUnreadItemCount++;
}

buffer.add(rssItem);
if (buffer.size() >= bufferSize) {
Log.v(TAG, "onNext() buffer size exceeded - insert items: " + buffer.size());
performDatabaseBatchInsert(mDbConn, buffer);
}
}
Expand All @@ -201,7 +204,7 @@ public void onError(@NonNull Throwable e) {

@Override
public void onComplete() {
Log.v(TAG, "onComplete() called");
Log.v(TAG, "onComplete() called - items: " + buffer.size());
performDatabaseBatchInsert(mDbConn, buffer);

//If no exception occurs, set the number of updated items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.util.Log;
import android.view.KeyEvent;

import androidx.annotation.IntegerRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
Expand All @@ -36,15 +37,18 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.events.podcast.ExitPlayback;
import de.luhmer.owncloudnewsreader.events.podcast.NewPodcastPlaybackListener;
import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent;
import de.luhmer.owncloudnewsreader.events.podcast.RegisterVideoOutput;
Expand Down Expand Up @@ -134,6 +138,9 @@ public boolean isActive() {
return mPlaybackService != null;
}

static final AtomicLong NEXT_ID = new AtomicLong(0);
final long id = NEXT_ID.getAndIncrement();

@Nullable
@Override
public BrowserRoot onGetRoot(@NonNull String s, int i, @Nullable Bundle bundle) {
Expand Down Expand Up @@ -203,23 +210,14 @@ public void onLoadChildren(@NonNull String s, @NonNull Result<List<MediaBrowserC

@Override
public boolean onUnbind(Intent intent) {
Log.d(TAG, "onUnbind() called with: intent = [" + intent + "]");
if (!isActive()) {
Log.v(TAG, "Stopping PodcastPlaybackService because of inactivity");
stopSelf();

if (mSession != null) {
mSession.release();
}
}
Log.d(TAG, "onUnbind() called with: intent = [" + intent + "] - ID: " + id);
return super.onUnbind(intent);
}

@Override
public void onCreate() {
super.onCreate();
Log.v(TAG, "onCreate PodcastPlaybackService");

Log.v(TAG, "onCreate PodcastPlaybackService - ID: " + id);

// pause podcast when phone is ringing
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
Expand Down Expand Up @@ -261,7 +259,18 @@ public void onCreate() {

@Override
public void onDestroy() {
Log.v(TAG, "onDestroy PodcastPlaybackService");
Log.v(TAG, "onDestroy PodcastPlaybackService - ID: " + id);

if (!isActive()) {
Log.v(TAG, "Stopping PodcastPlaybackService/PlaybackService because of inactivity");
stopSelf();

if (mSession != null) {
mSession.release();
}
} else {
Log.v(TAG, "Stopping PlaybackService is not active - skip exit");
}

try {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
Expand Down Expand Up @@ -398,6 +407,10 @@ private void endCurrentMediaPlayback() {
abandonAudioFocus();
}

@Subscribe
public void onEvent(ExitPlayback event) {
this.endCurrentMediaPlayback();
}

@Subscribe
public void onEvent(TogglePlayerStateEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void playbackSpeedChanged(float currentPlaybackSpeed) {

@Override
public void seekTo(int position) {
//double totalDuration = mMediaPlayer.getDuration();
double totalDuration = mMediaPlayer.getDuration();
Log.d(TAG, "seekTo position: " + position + " totalDuration: " + totalDuration);
//int position = (int) ((totalDuration / 100d) * percent);
mMediaPlayer.seekTo(position);
}
Expand Down
19 changes: 17 additions & 2 deletions News-Android-App/src/main/res/layout/fragment_podcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@
android:textSize="18sp"
android:textColor="@color/divider_row_color"/>

<Button
android:id="@+id/btn_exit_podcast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/exit_playback"
android:textSize="18sp"
android:textColor="@color/primaryTextColor"
android:background="@color/colorPrimary"
android:layout_marginBottom="16dp"
android:layout_alignBottom="@id/tv_no_podcasts_available" />

<!--
<it.gmariotti.cardslib.library.view.CardGridView
android:layout_width="match_parent"
Expand Down Expand Up @@ -257,7 +269,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/primaryTextColor"
tools:text="00:00"
tools:text="000:00"
android:minWidth="50dp"
android:layout_gravity="center_vertical" />


Expand Down Expand Up @@ -295,7 +308,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/primaryTextColor"
tools:text="00:00"
android:gravity="right"
tools:text="000:00"
android:minWidth="50dp"
android:layout_gravity="center_vertical" />

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions News-Android-App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<!-- Podcast -->
<string name="no_podcast_selected">No podcast selected</string>
<string name="no_chapters_available">No chapters available</string>
<string name="exit_playback">Exit Player</string>
<string name="podcast_playback_speed_dialog_title">Playback Speed</string>
<string name="notification_downloading_podcast_title">Downloading podcast</string>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.android.tools.build:gradle:7.1.2'
}
}

Expand Down
6 changes: 6 additions & 0 deletions docker-nextcloud-test-instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ Start image with:
5. Setup News App
6. Add Nextcloud Account to your phone (in the nextcloud files app)
7. Use SSO in Nextcloud News App to access test instance


# Debug requests

curl -u admin http://localhost/index.php/apps/news/api/v1-2/items
curl -u admin http://localhost/index.php/apps/news/api/v1-2/items/updated?lastModified=1636295405&type=3&id=0 | jq '. | length'

0 comments on commit e41e159

Please sign in to comment.