mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-16 23:40:31 +00:00
Finish async generates
This commit is contained in:
parent
542a7f212d
commit
ed3820bec0
2 changed files with 11 additions and 7 deletions
|
@ -231,26 +231,27 @@ fun <T: V8Value> V8ValuePromise.toV8ValueBlocking(plugin: V8Plugin): T {
|
||||||
return promiseResult!!;
|
return promiseResult!!;
|
||||||
}
|
}
|
||||||
fun <T: V8Value> V8ValuePromise.toV8ValueAsync(plugin: V8Plugin): V8Deferred<T> {
|
fun <T: V8Value> V8ValuePromise.toV8ValueAsync(plugin: V8Plugin): V8Deferred<T> {
|
||||||
|
val underlyingDef = CompletableDeferred<T>();
|
||||||
val def = if(this.has("estDuration"))
|
val def = if(this.has("estDuration"))
|
||||||
V8Deferred(CompletableDeferred<T>(),
|
V8Deferred(underlyingDef,
|
||||||
this.getOrDefault(plugin.config, "estDuration", "toV8ValueAsync", -1) ?: -1);
|
this.getOrDefault(plugin.config, "estDuration", "toV8ValueAsync", -1) ?: -1);
|
||||||
else
|
else
|
||||||
V8Deferred<T>(CompletableDeferred<T>());
|
V8Deferred<T>(underlyingDef);
|
||||||
|
|
||||||
val promise = this;
|
val promise = this;
|
||||||
plugin.busy {
|
plugin.busy {
|
||||||
this.register(object: IV8ValuePromise.IListener {
|
this.register(object: IV8ValuePromise.IListener {
|
||||||
override fun onFulfilled(p0: V8Value?) {
|
override fun onFulfilled(p0: V8Value?) {
|
||||||
plugin.resolvePromise(promise);
|
plugin.resolvePromise(promise);
|
||||||
def.complete(p0 as T);
|
underlyingDef.complete(p0 as T);
|
||||||
}
|
}
|
||||||
override fun onRejected(p0: V8Value?) {
|
override fun onRejected(p0: V8Value?) {
|
||||||
plugin.resolvePromise(promise);
|
plugin.resolvePromise(promise);
|
||||||
def.completeExceptionally(NotImplementedError("onRejected promise not implemented.."));
|
underlyingDef.completeExceptionally(NotImplementedError("onRejected promise not implemented.."));
|
||||||
}
|
}
|
||||||
override fun onCatch(p0: V8Value?) {
|
override fun onCatch(p0: V8Value?) {
|
||||||
plugin.resolvePromise(promise);
|
plugin.resolvePromise(promise);
|
||||||
def.completeExceptionally(NotImplementedError("onCatch promise not implemented.."));
|
underlyingDef.completeExceptionally(NotImplementedError("onCatch promise not implemented.."));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -277,7 +278,7 @@ class V8Deferred<T>(val deferred: Deferred<T>, val estDuration: Int = -1): Defer
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun <R> merge(scope: CoroutineScope, defs: List<V8Deferred<T>> conversion: (result: List<T>)->R): V8Deferred<R> {
|
fun <T, R> merge(scope: CoroutineScope, defs: List<V8Deferred<T>>, conversion: (result: List<T>)->R): V8Deferred<R> {
|
||||||
|
|
||||||
var amount = -1;
|
var amount = -1;
|
||||||
for(def in defs)
|
for(def in defs)
|
||||||
|
|
|
@ -696,10 +696,13 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
||||||
Logger.i(TAG, "Loading AudioSource [DashRaw]");
|
Logger.i(TAG, "Loading AudioSource [DashRaw]");
|
||||||
if(audioSource.hasGenerate) {
|
if(audioSource.hasGenerate) {
|
||||||
findViewTreeLifecycleOwner()?.lifecycle?.coroutineScope?.launch(Dispatchers.IO) {
|
findViewTreeLifecycleOwner()?.lifecycle?.coroutineScope?.launch(Dispatchers.IO) {
|
||||||
|
val scope = this;
|
||||||
var startId = -1;
|
var startId = -1;
|
||||||
try {
|
try {
|
||||||
|
val plugin = audioSource.getUnderlyingPlugin() ?: return@launch;
|
||||||
startId = audioSource.getUnderlyingPlugin()?.getUnderlyingPlugin()?.runtimeId ?: -1;
|
startId = audioSource.getUnderlyingPlugin()?.getUnderlyingPlugin()?.runtimeId ?: -1;
|
||||||
val generated = audioSource.generate();
|
val generatedDef = plugin.busy { audioSource.generateAsync(scope); }
|
||||||
|
val generated = generatedDef.await();
|
||||||
if(generated != null) {
|
if(generated != null) {
|
||||||
val dataSource = if(audioSource is JSSource && (audioSource.requiresCustomDatasource))
|
val dataSource = if(audioSource is JSSource && (audioSource.requiresCustomDatasource))
|
||||||
audioSource.getHttpDataSourceFactory()
|
audioSource.getHttpDataSourceFactory()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue