Compare commits
2 Commits
e823fc9d94
...
feature/st
| Author | SHA1 | Date | |
|---|---|---|---|
| ab07086fcb | |||
| 096c676ce2 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,3 +10,5 @@ captures/
|
|||||||
*.apk
|
*.apk
|
||||||
*.ap_
|
*.ap_
|
||||||
*.aab
|
*.aab
|
||||||
|
# David
|
||||||
|
app/src/main/jniLibs
|
||||||
|
|||||||
@@ -562,13 +562,34 @@ class LockstepViewModel(
|
|||||||
app.playlistRepository.syncPlaylistDetail(playlistId)
|
app.playlistRepository.syncPlaylistDetail(playlistId)
|
||||||
null
|
null
|
||||||
} catch (e: LockstepApiException) {
|
} catch (e: LockstepApiException) {
|
||||||
e.message ?: "Load failed"
|
syncPlaylistDetailErrorForLibraryOpen(playlistId, e)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.message ?: "Load failed"
|
syncPlaylistDetailErrorForLibraryOpen(playlistId, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playlist detail fetch is best-effort when opening from the library. Unauthorized responses mean
|
||||||
|
* the token is stale; cached jukebox rows (if any) are still valid for pairing and playback.
|
||||||
|
*/
|
||||||
|
private fun syncPlaylistDetailErrorForLibraryOpen(playlistId: String, e: Exception): String? {
|
||||||
|
if (isPlaylistDetailHttp401(e)) {
|
||||||
|
Log.w(TAG, "syncPlaylistDetail unauthorized for $playlistId, opening from jukebox cache", e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (app.playlistRepository.getTracks(playlistId).isNotEmpty()) {
|
||||||
|
Log.w(TAG, "syncPlaylistDetail failed for $playlistId, using cached tracks", e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return e.message ?: "Load failed"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isPlaylistDetailHttp401(e: Exception): Boolean {
|
||||||
|
val msg = e.message ?: return false
|
||||||
|
return msg.contains("HTTP 401", ignoreCase = true)
|
||||||
|
}
|
||||||
|
|
||||||
fun completeOnboarding() {
|
fun completeOnboarding() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
prefs.setOnboardingComplete(true)
|
prefs.setOnboardingComplete(true)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public final class LibPasada {
|
|||||||
if (loaded) {
|
if (loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.loadLibrary("pasada");
|
System.loadLibrary("lockstep-native");
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,4 +72,7 @@ public final class LibPasada {
|
|||||||
|
|
||||||
/** Register listener for async events raised from the audio/native thread. */
|
/** Register listener for async events raised from the audio/native thread. */
|
||||||
public static native void setPlaybackListener(PasadaPlaybackListener listener);
|
public static native void setPlaybackListener(PasadaPlaybackListener listener);
|
||||||
|
|
||||||
|
/** native version string */
|
||||||
|
public static native String getVersion();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ public interface PasadaPlaybackListener {
|
|||||||
/** Current track reached end; service should advance queue and call {@link LibPasada#play}. */
|
/** Current track reached end; service should advance queue and call {@link LibPasada#play}. */
|
||||||
void onTrackFinished();
|
void onTrackFinished();
|
||||||
|
|
||||||
|
void onTrackClosed(int fd);
|
||||||
|
|
||||||
/** Decode / Oboe / pipeline failure; service should stop safely and surface error. */
|
/** Decode / Oboe / pipeline failure; service should stop safely and surface error. */
|
||||||
void onError(int errorCode, String message);
|
void onError(int errorCode, String message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import at.lockstep.player.LockstepApplication
|
|||||||
import at.lockstep.player.MainActivity
|
import at.lockstep.player.MainActivity
|
||||||
import at.lockstep.player.R
|
import at.lockstep.player.R
|
||||||
import at.lockstep.player.playback.engine.ExoPlayerMusicPlayerEngine
|
import at.lockstep.player.playback.engine.ExoPlayerMusicPlayerEngine
|
||||||
|
import at.lockstep.player.playback.engine.PasadaMusicPlayerEngine
|
||||||
import at.lockstep.player.playback.engine.MusicPlayerEngine
|
import at.lockstep.player.playback.engine.MusicPlayerEngine
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -204,7 +205,8 @@ class PlaybackService : Service() {
|
|||||||
engine?.let {
|
engine?.let {
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
return ExoPlayerMusicPlayerEngine(this)
|
//return ExoPlayerMusicPlayerEngine(this)
|
||||||
|
return PasadaMusicPlayerEngine(this)
|
||||||
.also {
|
.also {
|
||||||
it.setListener(engineListener)
|
it.setListener(engineListener)
|
||||||
it.initSession()
|
it.initSession()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.net.Uri
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
|
import android.util.Log
|
||||||
import at.lockstep.player.pasada.LibPasada
|
import at.lockstep.player.pasada.LibPasada
|
||||||
import at.lockstep.player.pasada.PasadaPlaybackListener
|
import at.lockstep.player.pasada.PasadaPlaybackListener
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@@ -35,12 +36,18 @@ class PasadaMusicPlayerEngine(
|
|||||||
private val nativeListener =
|
private val nativeListener =
|
||||||
object : PasadaPlaybackListener {
|
object : PasadaPlaybackListener {
|
||||||
override fun onTrackFinished() {
|
override fun onTrackFinished() {
|
||||||
|
Log.i(TAG, "PasadaPlaybackListener.onTrackFinished()")
|
||||||
pendingStart = false
|
pendingStart = false
|
||||||
mainHandler.post {
|
mainHandler.post {
|
||||||
listener?.onPlaybackEnded()
|
listener?.onPlaybackEnded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTrackClosed(fd: Int) {
|
||||||
|
Log.i(TAG, "onTrackClosed: native returned fd=$fd")
|
||||||
|
// we handle parcel close() separately
|
||||||
|
}
|
||||||
|
|
||||||
override fun onError(
|
override fun onError(
|
||||||
errorCode: Int,
|
errorCode: Int,
|
||||||
message: String,
|
message: String,
|
||||||
@@ -51,13 +58,18 @@ class PasadaMusicPlayerEngine(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val TAG = "PasadaMusicPlayerEngine"
|
||||||
|
|
||||||
override fun initSession() {
|
override fun initSession() {
|
||||||
if (sessionInitialized) {
|
if (sessionInitialized) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Log.i(TAG, "LibPasada.loadNative() ...")
|
||||||
LibPasada.loadNative()
|
LibPasada.loadNative()
|
||||||
LibPasada.setPlaybackListener(nativeListener)
|
LibPasada.setPlaybackListener(nativeListener)
|
||||||
|
Log.i(TAG, "LibPasada.init() ...")
|
||||||
LibPasada.init()
|
LibPasada.init()
|
||||||
|
Log.i(TAG, "LibPasada.init() done.")
|
||||||
sessionInitialized = true
|
sessionInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +143,9 @@ class PasadaMusicPlayerEngine(
|
|||||||
|
|
||||||
private fun startPendingTrack() {
|
private fun startPendingTrack() {
|
||||||
val fd = trackFd ?: return
|
val fd = trackFd ?: return
|
||||||
|
Log.i(TAG, "LibPasada.play(fd=$fd, offset=$trackOffset, length=$trackLength) ...")
|
||||||
LibPasada.play(fd, trackOffset, trackLength)
|
LibPasada.play(fd, trackOffset, trackLength)
|
||||||
|
Log.i(TAG, "LibPasada.play() done.")
|
||||||
pendingStart = false
|
pendingStart = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
app/src/main/java/com/rex/logger/NdkLogger.java
Normal file
64
app/src/main/java/com/rex/logger/NdkLogger.java
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.rex.logger;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
//import proguard.annotation.KeepName;
|
||||||
|
|
||||||
|
//@KeepName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gather native log into logback, for easy control save log into SDCard
|
||||||
|
*/
|
||||||
|
public class NdkLogger {
|
||||||
|
private static final String TAG = "NDK";
|
||||||
|
|
||||||
|
//@KeepName
|
||||||
|
public static void logWrite(int level, String message) {
|
||||||
|
//sLogger.trace("level:{} message:{}", level, message);
|
||||||
|
switch (level) {
|
||||||
|
case Log.VERBOSE:
|
||||||
|
Log.v(TAG, message);
|
||||||
|
break;
|
||||||
|
case Log.DEBUG:
|
||||||
|
Log.d(TAG, message);
|
||||||
|
break;
|
||||||
|
case Log.INFO:
|
||||||
|
Log.i(TAG, message);
|
||||||
|
break;
|
||||||
|
case Log.WARN:
|
||||||
|
Log.w(TAG, message);
|
||||||
|
break;
|
||||||
|
case Log.ERROR:
|
||||||
|
Log.e(TAG, message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("ndk-logger");
|
||||||
|
} catch (UnsatisfiedLinkError ex) {
|
||||||
|
Log.e(TAG, "Failed to load library.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getABI() { return native_getABI(); }
|
||||||
|
private static native String native_getABI();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user