Skip to content

Commit

Permalink
4.10.1 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed May 6, 2024
1 parent b719267 commit eeea4bf
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 355 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ android {
// Version code schema (not used):
// "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395
versionCode 3020138
versionName "4.10.0"
versionCode 3020139
versionName "4.10.1"

def commit = ""
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ class LocalMediaPlayer(context: Context, callback: PSMPCallback) : MediaPlayerBa
}

companion object {
private const val TAG = "LclPlaybackSvcMPlayer"
private const val TAG = "LocalMediaPlayer"

// from wrapper
const val BUFFERING_STARTED: Int = -1
Expand Down
372 changes: 64 additions & 308 deletions app/src/main/java/ac/mdiq/podcini/storage/database/PodDBAdapter.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ac.mdiq.podcini.ui.actions.actionbutton
import ac.mdiq.podcini.R
import ac.mdiq.podcini.net.download.service.DownloadRequestCreator.getMediafilePath
import ac.mdiq.podcini.net.download.service.DownloadRequestCreator.getMediafilename
import ac.mdiq.podcini.playback.AudioMediaOperation.MergeAudios
import ac.mdiq.podcini.util.AudioMediaOperation.mergeAudios
import ac.mdiq.podcini.storage.DBWriter
import ac.mdiq.podcini.storage.DBWriter.persistFeedItem
import ac.mdiq.podcini.storage.model.feed.FeedItem
Expand Down Expand Up @@ -77,9 +77,7 @@ class TTSActionButton(item: FeedItem) : ItemActionButton(item) {
val result = tts?.setLanguage(Locale(item.feed!!.language!!))
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.w(TAG, "TTS language not supported ${item.feed?.language} $result")
withContext(Dispatchers.Main) {
Toast.makeText(context, context.getString(R.string.language_not_supported_by_tts) + " ${item.feed?.language} $result", Toast.LENGTH_LONG).show()
}
withContext(Dispatchers.Main) { Toast.makeText(context, context.getString(R.string.language_not_supported_by_tts) + " ${item.feed?.language} $result", Toast.LENGTH_LONG).show() }
}
}

Expand Down Expand Up @@ -117,9 +115,7 @@ class TTSActionButton(item: FeedItem) : ItemActionButton(item) {
status = tts?.synthesizeToFile(chunk, null, tempFile, tempFile.absolutePath) ?: 0
Log.d(TAG, "status: $status chunk: ${chunk.substring(0, min(80, chunk.length))}")
if (status == TextToSpeech.ERROR) {
withContext(Dispatchers.Main) {
Toast.makeText(context, "Error generating audio file $tempFile.absolutePath", Toast.LENGTH_LONG).show()
}
withContext(Dispatchers.Main) { Toast.makeText(context, "Error generating audio file $tempFile.absolutePath", Toast.LENGTH_LONG).show() }
break
}
startIndex += chunkLength
Expand All @@ -131,7 +127,7 @@ class TTSActionButton(item: FeedItem) : ItemActionButton(item) {
processing = 0.85f
EventBus.getDefault().post(updated(item))
if (status == TextToSpeech.SUCCESS) {
MergeAudios(parts.toTypedArray(), mediaFile.absolutePath, null)
mergeAudios(parts.toTypedArray(), mediaFile.absolutePath, null)

// if (mediaFile.exists()) mediaFile.delete()
// if (!mediaFile.exists()) {
Expand All @@ -156,7 +152,7 @@ class TTSActionButton(item: FeedItem) : ItemActionButton(item) {
f.delete()
}
ttsWorking = false
} else Toast.makeText(context, R.string.episode_has_no_content, Toast.LENGTH_LONG).show()
} else withContext(Dispatchers.Main) { Toast.makeText(context, R.string.episode_has_no_content, Toast.LENGTH_LONG).show() }

item.setPlayed(false)
processing = 1f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ class EpisodeHomeFragment : Fragment() {
val result = tts?.setLanguage(Locale(currentItem!!.feed!!.language!!))
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.w(TAG, "TTS language not supported ${currentItem?.feed?.language}")
Toast.makeText(context, getString(R.string.language_not_supported_by_tts) + " ${currentItem?.feed?.language}", Toast.LENGTH_LONG).show()
requireActivity().runOnUiThread {
Toast.makeText(context, getString(R.string.language_not_supported_by_tts) + " ${currentItem?.feed?.language}", Toast.LENGTH_LONG).show()
}
}
}
ttsReady = true
// semaphore.release()
Log.d(TAG, "TTS init success")
} else {
Log.w(TAG, "TTS init failed")
Toast.makeText(context, R.string.tts_init_failed, Toast.LENGTH_LONG).show()
requireActivity().runOnUiThread {Toast.makeText(context, R.string.tts_init_failed, Toast.LENGTH_LONG).show() }
}
}
}
Expand All @@ -171,9 +173,9 @@ class EpisodeHomeFragment : Fragment() {
// super.onPrepareMenu(menu)
Log.d(TAG, "onPrepareMenu called")
val textSpeech = menu.findItem(R.id.text_speech)
textSpeech?.isVisible = readMode
if (readMode) {
if (ttsPlaying) textSpeech?.setIcon(R.drawable.ic_pause) else textSpeech?.setIcon(R.drawable.ic_play_24dp)
textSpeech?.isVisible = readMode && tts != null
if (textSpeech?.isVisible == true) {
if (ttsPlaying) textSpeech.setIcon(R.drawable.ic_pause) else textSpeech.setIcon(R.drawable.ic_play_24dp)
}
menu.findItem(R.id.share_notes)?.setVisible(readMode)
menu.findItem(R.id.switchJS)?.setVisible(!readMode)
Expand Down Expand Up @@ -215,7 +217,8 @@ class EpisodeHomeFragment : Fragment() {
}
} else ttsPlaying = false
updateAppearance()
}
} else Toast.makeText(context, R.string.tts_not_available, Toast.LENGTH_LONG).show()

return true
}
R.id.share_notes -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,26 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba
adapter.endSelectMode()
true
}
return binding.root
}

ioScope.launch {
if (!ttsReady) {
initializeTTS(requireContext())
semaphore.acquire()
private val semaphore = Semaphore(0)
private fun initializeTTS(context: Context) {
Log.d(TAG, "starting TTS")
if (tts == null) {
tts = TextToSpeech(context) { status: Int ->
if (status == TextToSpeech.SUCCESS) {
ttsReady = true
semaphore.release()
Log.d(TAG, "TTS init success")
} else {
Log.w(TAG, "TTS init failed")
requireActivity().runOnUiThread {
Toast.makeText(context, R.string.tts_init_failed, Toast.LENGTH_LONG).show()
}
}
}
}
return binding.root
}

override fun onDestroyView() {
Expand Down Expand Up @@ -523,14 +535,30 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba

@UnstableApi private fun loadItems() {
disposable?.dispose()

disposable = Observable.fromCallable<Feed?> { this.loadData() }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ result: Feed? ->
feed = result
Log.d(TAG, "loadItems subscribe called ${feed?.title}")
if (feed != null) {
var hasNonMediaItems = false
for (item in feed!!.items) {
if (item.media == null) {
hasNonMediaItems = true
break
}
}
if (hasNonMediaItems) {
ioScope.launch {
if (!ttsReady) {
initializeTTS(requireContext())
semaphore.acquire()
}
}
}
}
swipeActions.setFilter(feed?.itemFilter)
refreshHeaderView()
binding.progressBar.visibility = View.GONE
Expand Down Expand Up @@ -649,22 +677,5 @@ class FeedItemlistFragment : Fragment(), AdapterView.OnItemClickListener, Toolba
var tts: TextToSpeech? = null
var ttsReady = false
var ttsWorking = false
val semaphore = Semaphore(0)

fun initializeTTS(context: Context) {
Log.d(TAG, "starting TTS")
if (tts == null) {
tts = TextToSpeech(context) { status: Int ->
if (status == TextToSpeech.SUCCESS) {
ttsReady = true
semaphore.release()
Log.d(TAG, "TTS init success")
} else {
Log.w(TAG, "TTS init failed")
Toast.makeText(context, R.string.tts_init_failed, Toast.LENGTH_LONG).show()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ac.mdiq.podcini.playback
package ac.mdiq.podcini.util

import java.io.*
import java.nio.ByteBuffer
import java.nio.ByteOrder

// converted to Kotlin from the java file: https://gist.github.com/DrustZ/d3d3fc8fcc1067433db4dd3079f8d187
object AudioMediaOperation {
fun MergeAudios(selection: Array<String>, outpath: String?, callback: OperationCallbacks?) {
fun mergeAudios(selection: Array<String>, outpath: String?, callback: OperationCallbacks?) {
var RECORDER_SAMPLERATE = 0
try {
val amplifyOutputStream = DataOutputStream(BufferedOutputStream(FileOutputStream(outpath)))
Expand Down Expand Up @@ -145,7 +145,7 @@ object AudioMediaOperation {
}

@Throws(IOException::class)
fun RawToWave(rawfn: String?, wavefn: String?) {
fun rawToWave(rawfn: String, wavefn: String) {
val rawFile = File(rawfn)
val waveFile = File(wavefn)
val rawData = ByteArray(rawFile.length().toInt())
Expand Down Expand Up @@ -233,8 +233,8 @@ object AudioMediaOperation {

@Throws(IOException::class)
fun writeString(output: DataOutputStream, value: String) {
for (i in 0 until value.length) {
output.write(value[i].code)
for (element in value) {
output.write(element.code)
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="web_content_not_available">Web content is not available</string>
<string name="language_not_supported_by_tts">The language is not supported by TTS</string>
<string name="tts_init_failed">TTS init failed</string>
<string name="tts_not_available">TTS engine not available</string>
<string name="episode_has_no_content">Episode has not content</string>

<string name="notification_permission_text">Since Android 13, top level notification is needed for normal refresh and playback. You may disallow notifications of sub-catergories at your wish.</string>
Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.10.1

* fixed crash issue when TTS engine is not available on device
* in feed item list view, only start TTS engine when some episodes have no media

## 4.10.0

* fixed media info on notification widget
Expand Down Expand Up @@ -54,7 +59,7 @@
## 4.9.0

* fixed bug of player always expands when changing audio
* migrated to media3's MediaSession and MediaLibraryService thought no new features added with this. some behavior might change or issues might arise, need to be mindful
* migrated to media3's MediaSession and MediaLibraryService though no new features added with this. some behavior might change or issues might arise, need to be mindful
* when video mode is temporarily audio only, click on image on audio player on a video episode also brings up the normal player detailed view
* added a menu action item in player detailed view to turn to fullscreen video for video episode
* added episode home view accessible right from episode info view. episode home view has two display modes: webpage or reader.
Expand Down
5 changes: 5 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/3020139.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Version 4.10.1 brings several changes:

* fixed crash issue when TTS engine is not available on device
* in feed item list view, only start TTS engine when some episodes have no media

0 comments on commit eeea4bf

Please sign in to comment.