Commit 20e2bd1a authored by Geoffrey Métais's avatar Geoffrey Métais

Provide context when launching LibVLC

parent 9fbe9a4a
......@@ -52,7 +52,7 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
return@launch
}
try {
val media = Media(VLCInstance.get(), mw.uri)
val media = Media(VLCInstance.get(this@PreviewVideoInputService), mw.uri)
val start = if (mw.length <= 0L) 0 else mw.length.random()/1000
media.addOption(":start-time=$start")
player.getVout()?.apply {
......
......@@ -41,8 +41,10 @@ object RendererDelegate : RendererDiscoverer.EventListener {
suspend fun start() {
if (started) return
val libVlc = VLCApplication.getAppContext()?.let {
withContext(Dispatchers.IO) { VLCInstance.get(it) }
} ?: return
started = true
val libVlc = withContext(Dispatchers.IO) { VLCInstance.get() }
for (discoverer in RendererDiscoverer.list(libVlc)) {
val rd = RendererDiscoverer(libVlc, discoverer.name)
discoverers.add(rd)
......
......@@ -103,7 +103,7 @@ public class VLCApplication extends Application {
AudioUtil.prepareCacheFolder(getAppContext());
if (!VLCInstance.testCompatibleCPU(getAppContext())) return;
Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks);
Dialog.setCallbacks(VLCInstance.get(instance), mDialogCallbacks);
}
});
}
......
package org.videolan.vlc.gui;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
......@@ -270,15 +271,15 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
}
private class ParseTracksTask extends AsyncTask<Void, Void, Media> {
final Context context = getApplicationContext();
@Override
protected Media doInBackground(Void... params) {
final LibVLC libVlc = VLCInstance.get();
if (libVlc == null || isCancelled())
return null;
final LibVLC libVlc = VLCInstance.get(context);
if (libVlc == null || isCancelled()) return null;
Media media = new Media(libVlc, ((MediaWrapper)mItem).getUri());
final Media media = new Media(libVlc, ((MediaWrapper)mItem).getUri());
media.parse();
return media;
......@@ -287,8 +288,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
@Override
protected void onPostExecute(Media media) {
mParseTracksTask = null;
if (media == null || isCancelled())
return;
if (media == null || isCancelled()) return;
boolean hasSubs = false;
final int trackCount = media.getTrackCount();
List<Media.Track> tracks = new LinkedList<>();
......@@ -299,8 +299,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
}
media.release();
mAdapter.setTracks(tracks);
if (hasSubs)
mBinding.infoSubtitles.setVisibility(View.VISIBLE);
if (hasSubs) mBinding.infoSubtitles.setVisibility(View.VISIBLE);
}
@Override
......
......@@ -207,7 +207,7 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
}
private fun newMediaPlayer() : MediaPlayer {
return MediaPlayer(VLCInstance.get()).apply {
return MediaPlayer(VLCInstance.get(context)).apply {
setAudioDigitalOutputEnabled(VLCOptions.isAudioDigitalOutputEnabled(settings))
VLCOptions.getAout(settings)?.let { setAudioOutput(it) }
setRenderer(PlaybackService.renderer.value)
......
......@@ -293,7 +293,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
return
}
val start = getStartTime(mw)
val media = Media(VLCInstance.get(), uri)
val media = Media(VLCInstance.get(service), uri)
media.addOption(":start-time=$start")
VLCOptions.setMediaOptions(media, ctx, flags or mw.flags)
/* keeping only video during benchmark */
......
......@@ -77,7 +77,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
}
protected open fun initBrowser() {
if (mediabrowser == null) mediabrowser = MediaBrowser(VLCInstance.get(), this, browserHandler)
if (mediabrowser == null) mediabrowser = MediaBrowser(VLCInstance.get(context), this, browserHandler)
}
open fun fetch() {
......
......@@ -20,10 +20,10 @@
package org.videolan.vlc.util;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.util.Log;
import org.videolan.libvlc.LibVLC;
......@@ -35,14 +35,15 @@ import org.videolan.vlc.gui.CompatErrorActivity;
public class VLCInstance {
public final static String TAG = "VLC/UiTools/VLCInstance";
@SuppressLint("StaticFieldLeak")
private static LibVLC sLibVLC = null;
/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException {
public synchronized static LibVLC get(Context ctx) throws IllegalStateException {
if (sLibVLC == null) {
Thread.setDefaultUncaughtExceptionHandler(new VLCCrashHandler());
final Context context = VLCApplication.getAppContext();
final Context context = ctx.getApplicationContext();
if(!VLCUtil.hasCompatibleCPU(context)) {
Log.e(TAG, VLCUtil.getErrorMsg());
throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment