Fixing gradle dependency issues on android, minor warning fixes

This commit is contained in:
advplyr
2022-04-19 19:25:16 -05:00
parent 379612d874
commit f65f7b01c3
16 changed files with 94 additions and 131 deletions
@@ -12,7 +12,7 @@ class CastOptionsProvider : OptionsProvider {
override fun getCastOptions(context: Context): CastOptions {
Log.d("CastOptionsProvider", "getCastOptions")
var appId = "FD1F76C5"
var defaultId =CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
// var defaultId =CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
return CastOptions.Builder()
.setReceiverApplicationId(appId).setCastMediaOptions(
CastMediaOptions.Builder()
@@ -5,7 +5,6 @@ import android.app.DownloadManager
import android.content.*
import android.content.pm.PackageManager
import android.os.*
import android.os.StrictMode.VmPolicy
import android.util.Log
import androidx.core.app.ActivityCompat
import com.anggrayudi.storage.SimpleStorage
@@ -132,7 +131,7 @@ class MainActivity : BridgeActivity() {
fun stopMyService() {
if (mBounded) {
mConnection?.let { unbindService(it) };
mConnection.let { unbindService(it) };
mBounded = false;
}
val stopIntent = Intent(this, PlayerNotificationService::class.java)
@@ -105,7 +105,6 @@ class FolderScanner(var ctx: Context) {
var coverAbsolutePath:String? = null
var filesInFolder = itemFolder.search(false, DocumentFileType.FILE, arrayOf("audio/*", "image/*"))
var isPodcast = localFolder.mediaType == "podcast"
var existingLocalFilesRemoved = existingLocalFiles.filter { elf ->
filesInFolder.find { fif -> DeviceManager.getBase64Id(fif.id) == elf.id } == null // File was not found in media item folder
@@ -116,8 +115,8 @@ class FolderScanner(var ctx: Context) {
}
filesInFolder.forEach { file ->
var mimeType = file?.mimeType ?: ""
var filename = file?.name ?: ""
var mimeType = file.mimeType ?: ""
var filename = file.name ?: ""
var isAudio = mimeType.startsWith("audio")
Log.d(tag, "Found $mimeType file $filename in folder $itemFolderName")
@@ -77,7 +77,7 @@ class CastManager constructor(val mainActivity:Activity) {
builder.setTitle(it.friendlyName)
}
builder.setOnDismissListener { callback.onCancel() }
builder.setPositiveButton("Stop Casting") { dialog, which -> endSession(true, null) }
builder.setPositiveButton("Stop Casting") { _, _ -> endSession(true, null) }
builder.show()
}
}
@@ -286,14 +286,14 @@ class CastManager constructor(val mainActivity:Activity) {
}
}
override fun onSessionStartFailed(castSession: CastSession, errCode: Int) {
if (callback.onSessionStartFailed(errCode)) {
override fun onSessionStartFailed(castSession: CastSession, error: Int) {
if (callback.onSessionStartFailed(error)) {
getSessionManager()?.removeSessionManagerListener(this, CastSession::class.java)
}
}
override fun onSessionEnded(castSession: CastSession, errCode: Int) {
if (callback.onSessionEndedBeforeStart(errCode)) {
override fun onSessionEnded(castSession: CastSession, error: Int) {
if (callback.onSessionEndedBeforeStart(error)) {
getSessionManager()?.removeSessionManagerListener(this, CastSession::class.java)
}
}
@@ -149,7 +149,7 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
private fun toMediaQueueItem(mediaItem: MediaItem): MediaQueueItem {
// The MediaQueueItem you build is expected to be in the tag.
return (mediaItem.playbackProperties!!.tag as MediaQueueItem?)!!
return (mediaItem.localConfiguration!!.tag as MediaQueueItem?)!!
}
@JvmName("setRemoteMediaClient1")
@@ -373,7 +373,6 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
listeners.queueEvent(
EVENT_POSITION_DISCONTINUITY
) { listener: Listener ->
listener.onPositionDiscontinuity(DISCONTINUITY_REASON_AUTO_TRANSITION)
listener.onPositionDiscontinuity(
oldPosition, newPosition, DISCONTINUITY_REASON_AUTO_TRANSITION)
}
@@ -385,9 +384,6 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
}
}
if (updateTracksAndSelectionsAndNotifyIfChanged()) {
listeners.queueEvent(
EVENT_TRACKS_CHANGED
) { listener: Listener -> listener.onTracksChanged(currentTrackGroups, currentTrackSelections) }
listeners.queueEvent(
EVENT_TRACKS_CHANGED) { listener: Listener -> listener.onTracksInfoChanged(currentTracksInfo) }
}
@@ -640,8 +636,6 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
pendingSeekWindowIndex = C.INDEX_UNSET
pendingSeekPositionMs = C.TIME_UNSET
listeners.sendEvent( /* eventFlag= */C.INDEX_UNSET) { obj: Player.Listener -> obj.onSeekProcessed() }
// Playback state change will send metadata to client and stop seek loading
listeners.sendEvent(EVENT_PLAYBACK_STATE_CHANGED) { obj: Player.Listener -> obj.onPlaybackStateChanged(currentPlaybackState) }
}
@@ -651,27 +645,27 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
// We assume the default position is 0. There is no support for seeking to the default position
// in RemoteMediaClient.
var positionMs = if (positionMs != C.TIME_UNSET) positionMs else 0
var positionMsFinal = if (positionMs != C.TIME_UNSET) positionMs else 0
if (mediaStatus != null) {
if (currentMediaItemIndex != mediaItemIndex) {
Log.d(tag, "seekTo: Changing media item index from $currentMediaItemIndex to $mediaItemIndex")
remoteMediaClient?.queueJumpToItem(myCurrentTimeline.getPeriod(mediaItemIndex, period).uid as Int, positionMs, JSONObject())?.setResultCallback(resultCb)
remoteMediaClient?.queueJumpToItem(myCurrentTimeline.getPeriod(mediaItemIndex, period).uid as Int, positionMsFinal, JSONObject())?.setResultCallback(resultCb)
} else {
Log.d(tag, "seekTo: Same media index seek to position $positionMs")
var mediaSeekOptions = MediaSeekOptions.Builder().setPosition(positionMs).build()
Log.d(tag, "seekTo: Same media index seek to position $positionMsFinal")
var mediaSeekOptions = MediaSeekOptions.Builder().setPosition(positionMsFinal).build()
remoteMediaClient?.seek(mediaSeekOptions)?.setResultCallback(resultCb)
}
val oldPosition = getCurrentPositionInfo()
pendingSeekCount++
pendingSeekWindowIndex = mediaItemIndex
pendingSeekPositionMs = positionMs
pendingSeekPositionMs = positionMsFinal
val newPosition = getCurrentPositionInfo()
listeners.queueEvent(
EVENT_POSITION_DISCONTINUITY
) { listener: Player.Listener ->
listener.onPositionDiscontinuity(oldPosition, newPosition, DISCONTINUITY_REASON_SEEK)
}
if (oldPosition.windowIndex != newPosition.windowIndex) {
if (oldPosition.mediaItemIndex != newPosition.mediaItemIndex) {
val mediaItem = currentTimeline.getWindow(mediaItemIndex, window).mediaItem
listeners.queueEvent(
EVENT_MEDIA_ITEM_TRANSITION
@@ -680,7 +674,8 @@ class CastPlayer(var castContext: CastContext) : BasePlayer() {
updateAvailableCommandsAndNotifyIfChanged()
} else if (pendingSeekCount == 0) {
Log.w(tag, "seekTo Media Status is null")
listeners.queueEvent( /* eventFlag= */C.INDEX_UNSET) { obj: Player.Listener -> obj.onSeekProcessed() }
// Playback state change will send metadata to client and stop seek loading
listeners.sendEvent(EVENT_PLAYBACK_STATE_CHANGED) { obj: Player.Listener -> obj.onPlaybackStateChanged(currentPlaybackState) }
}
listeners.flushEvents()
}
@@ -157,7 +157,7 @@ class MediaSessionCallback(var playerNotificationService:PlayerNotificationServi
}
}
else -> {
Log.d(tag, "KeyCode:${keyEvent?.getKeyCode()}")
Log.d(tag, "KeyCode:${keyEvent.getKeyCode()}")
return false
}
}
@@ -92,10 +92,10 @@ class PlayerListener(var playerNotificationService:PlayerNotificationService) :
}
}
fun calcPauseSeekBackTime() : Long {
private fun calcPauseSeekBackTime() : Long {
if (lastPauseTime <= 0) return 0
var time: Long = System.currentTimeMillis() - lastPauseTime
var seekback: Long = 0
var seekback: Long
if (time < 60000) seekback = 0
else if (time < 120000) seekback = 10000
else if (time < 300000) seekback = 15000
@@ -70,7 +70,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
lateinit var mediaManager: MediaManager
lateinit var apiHandler: ApiHandler
lateinit var mPlayer: SimpleExoPlayer
lateinit var mPlayer: ExoPlayer
lateinit var currentPlayer:Player
var castPlayer:CastPlayer? = null
@@ -171,11 +171,11 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
1000 * 20 // 20s playback rebuffer
).build()
var simpleExoPlayerBuilder = SimpleExoPlayer.Builder(this)
simpleExoPlayerBuilder.setLoadControl(customLoadControl)
simpleExoPlayerBuilder.setSeekBackIncrementMs(10000)
simpleExoPlayerBuilder.setSeekForwardIncrementMs(10000)
mPlayer = simpleExoPlayerBuilder.build()
mPlayer = ExoPlayer.Builder(this)
.setLoadControl(customLoadControl)
.setSeekBackIncrementMs(10000)
.setSeekForwardIncrementMs(10000)
.build()
mPlayer.setHandleAudioBecomingNoisy(true)
mPlayer.addListener(PlayerListener(this))
var audioAttributes:AudioAttributes = AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).setContentType(C.CONTENT_TYPE_SPEECH).build()
@@ -246,14 +246,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
mediaSessionConnector = MediaSessionConnector(mediaSession)
val queueNavigator: TimelineQueueNavigator = object : TimelineQueueNavigator(mediaSession) {
override fun getMediaDescription(player: Player, windowIndex: Int): MediaDescriptionCompat {
var builder = MediaDescriptionCompat.Builder()
return MediaDescriptionCompat.Builder()
.setMediaId(currentPlaybackSession!!.id)
.setTitle(currentPlaybackSession!!.displayTitle)
.setSubtitle(currentPlaybackSession!!.displayAuthor)
.setIconUri(currentPlaybackSession!!.getCoverUri())
return builder.build()
.setIconUri(currentPlaybackSession!!.getCoverUri()).build()
}
// .setMediaUri(currentPlaybackSession!!.getContentUri())
}
mediaSessionConnector.setEnabledPlaybackActions(
@@ -311,18 +309,16 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
if (mPlayer == currentPlayer) {
var mediaSource:MediaSource
var dataSourceFactory = DefaultHttpDataSource.Factory()
dataSourceFactory.setUserAgent(channelId)
if (playbackSession.isLocal) {
Log.d(tag, "Playing Local Item")
var dataSourceFactory = DefaultDataSourceFactory(ctx, channelId)
mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItems[0])
} else if (!playbackSession.isHLS) {
Log.d(tag, "Direct Playing Item")
var dataSourceFactory = DefaultDataSourceFactory(ctx, channelId)
mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItems[0])
} else {
Log.d(tag, "Playing HLS Item")
var dataSourceFactory = DefaultHttpDataSource.Factory()
dataSourceFactory.setUserAgent(channelId)
dataSourceFactory.setDefaultRequestProperties(hashMapOf("Authorization" to "Bearer ${DeviceManager.token}"))
mediaSource = HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItems[0])
}
@@ -426,12 +422,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
}
fun getCurrentTime() : Long {
if (currentPlayer.mediaItemCount > 1) {
var windowIndex = currentPlayer.currentWindowIndex
var currentTrackStartOffset = currentPlaybackSession?.getTrackStartOffsetMs(windowIndex) ?: 0L
return currentPlayer.currentPosition + currentTrackStartOffset
return if (currentPlayer.mediaItemCount > 1) {
val windowIndex = currentPlayer.currentMediaItemIndex
val currentTrackStartOffset = currentPlaybackSession?.getTrackStartOffsetMs(windowIndex) ?: 0L
currentPlayer.currentPosition + currentTrackStartOffset
} else {
return currentPlayer.currentPosition
currentPlayer.currentPosition
}
}
@@ -439,13 +435,13 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
return getCurrentTime() / 1000.0
}
fun getBufferedTime() : Long {
if (currentPlayer.mediaItemCount > 1) {
var windowIndex = currentPlayer.currentWindowIndex
var currentTrackStartOffset = currentPlaybackSession?.getTrackStartOffsetMs(windowIndex) ?: 0L
return currentPlayer.bufferedPosition + currentTrackStartOffset
private fun getBufferedTime() : Long {
return if (currentPlayer.mediaItemCount > 1) {
val windowIndex = currentPlayer.currentMediaItemIndex
val currentTrackStartOffset = currentPlaybackSession?.getTrackStartOffsetMs(windowIndex) ?: 0L
currentPlayer.bufferedPosition + currentTrackStartOffset
} else {
return currentPlayer.bufferedPosition
currentPlayer.bufferedPosition
}
}
@@ -23,8 +23,6 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
import java.util.*
@CapacitorPlugin(name = "AbsDownloader")
class AbsDownloader : Plugin() {
@@ -54,7 +52,7 @@ class AbsDownloader : Plugin() {
) {
@JsonIgnore
fun getDownloadRequest(): DownloadManager.Request {
var dlRequest = DownloadManager.Request(uri)
val dlRequest = DownloadManager.Request(uri)
dlRequest.setTitle(filename)
dlRequest.setDescription("Downloading to $localFolderName for book $itemTitle")
dlRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
@@ -86,21 +84,12 @@ class AbsDownloader : Plugin() {
folderScanner = FolderScanner(mainActivity)
apiHandler = ApiHandler(mainActivity)
var recieverEvent: (evt: String, id: Long) -> Unit = { evt: String, id: Long ->
if (evt == "complete") {
}
if (evt == "clicked") {
Log.d(tag, "Clicked $id back in the downloader")
}
}
mainActivity.registerBroadcastReceiver(recieverEvent)
Log.d(tag, "Build SDK ${Build.VERSION.SDK_INT}")
}
@PluginMethod
fun downloadLibraryItem(call: PluginCall) {
var libraryItemId = call.data.getString("libraryItemId").toString()
val libraryItemId = call.data.getString("libraryItemId").toString()
var episodeId = call.data.getString("episodeId").toString()
if (episodeId == "null") episodeId = ""
var localFolderId = call.data.getString("localFolderId").toString()
@@ -154,17 +143,6 @@ class AbsDownloader : Plugin() {
return if (cleanedRelPath.startsWith("_")) cleanedRelPath.substring(1) else cleanedRelPath
}
fun getAbMetadataText(libraryItem:LibraryItem):String {
var bookMedia = libraryItem.media as com.audiobookshelf.app.data.Book
var fileString = ";ABMETADATA1\n"
// fileString += "#libraryItemId=${libraryItem.id}\n"
// fileString += "title=${bookMedia.metadata.title}\n"
// fileString += "author=${bookMedia.metadata.authorName}\n"
// fileString += "narrator=${bookMedia.metadata.narratorName}\n"
// fileString += "series=${bookMedia.metadata.seriesName}\n"
return fileString
}
fun startLibraryItemDownload(libraryItem: LibraryItem, localFolder: LocalFolder, episode:PodcastEpisode?) {
if (libraryItem.mediaType == "book") {
var bookTitle = libraryItem.media.metadata.title
@@ -259,21 +237,21 @@ class AbsDownloader : Plugin() {
downloadItemPart.downloadId = downloadId
if (libraryItem.media.coverPath != null && libraryItem.media.coverPath?.isNotEmpty() == true) {
var serverPath = "/api/items/${libraryItem.id}/cover?format=jpeg"
var destinationFilename = "cover.jpg"
var destinationFile = File("$itemFolderPath/$destinationFilename")
serverPath = "/api/items/${libraryItem.id}/cover?format=jpeg"
destinationFilename = "cover.jpg"
destinationFile = File("$itemFolderPath/$destinationFilename")
if (destinationFile.exists()) {
Log.d(tag, "Podcast cover already exists - not downloading cover again")
} else {
var destinationUri = Uri.fromFile(destinationFile)
var downloadUri = Uri.parse("${DeviceManager.serverAddress}${serverPath}&token=${DeviceManager.token}")
var downloadItemPart = DownloadItemPart(DeviceManager.getBase64Id(destinationFile.absolutePath), destinationFilename, destinationFile.absolutePath, podcastTitle, serverPath, localFolder.name, localFolder.id, null,null, false, downloadUri, destinationUri, null, 0)
destinationUri = Uri.fromFile(destinationFile)
downloadUri = Uri.parse("${DeviceManager.serverAddress}${serverPath}&token=${DeviceManager.token}")
downloadItemPart = DownloadItemPart(DeviceManager.getBase64Id(destinationFile.absolutePath), destinationFilename, destinationFile.absolutePath, podcastTitle, serverPath, localFolder.name, localFolder.id, null,null, false, downloadUri, destinationUri, null, 0)
downloadItem.downloadItemParts.add(downloadItemPart)
var dlRequest = downloadItemPart.getDownloadRequest()
var downloadId = downloadManager.enqueue(dlRequest)
dlRequest = downloadItemPart.getDownloadRequest()
downloadId = downloadManager.enqueue(dlRequest)
downloadItemPart.downloadId = downloadId
}
}
@@ -110,7 +110,7 @@ class AbsFileSystem : Plugin() {
@PluginMethod
fun checkStoragePermission(call: PluginCall) {
var res = false
var res: Boolean
if (Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.P) {
res = SimpleStorage.hasStoragePermission(context)
Log.d(TAG, "checkStoragePermission: Check Storage Access $res")
@@ -222,32 +222,12 @@ class AbsFileSystem : Plugin() {
var docfile = DocumentFileCompat.fromUri(mainActivity, Uri.parse(contentUrl))
var success = docfile?.delete() == true
if (success) {
localLibraryItem?.media?.removeAudioTrack(trackLocalFileId)
localLibraryItem?.removeLocalFile(trackLocalFileId)
localLibraryItem.media.removeAudioTrack(trackLocalFileId)
localLibraryItem.removeLocalFile(trackLocalFileId)
DeviceManager.dbManager.saveLocalLibraryItem(localLibraryItem)
call.resolve(JSObject(jacksonMapper.writeValueAsString(localLibraryItem)))
} else {
call.resolve(JSObject("{\"success\":false}"))
}
}
fun checkUriExists(uri: Uri?): Boolean {
if (uri == null) return false
val resolver = context.contentResolver
var cursor: Cursor? = null
return try {
cursor = resolver.query(uri, null, null, null, null)
//cursor null: content Uri was invalid or some other error occurred
//cursor.moveToFirst() false: Uri was ok but no entry found.
(cursor != null && cursor.moveToFirst())
} catch (t: Throwable) {
false
} finally {
try {
cursor?.close()
} catch (t: Throwable) {
}
false
}
}
}
@@ -111,7 +111,7 @@ class ApiHandler(var ctx:Context) {
getRequest("/api/libraries") {
val libraries = mutableListOf<Library>()
if (it.has("value")) {
var array = it.getJSONArray("value")!!
var array = it.getJSONArray("value")
for (i in 0 until array.length()) {
val library = mapper.readValue<Library>(array.get(i).toString())
libraries.add(library)