Skip to content
Snippets Groups Projects
Commit f711e8bd authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Put the factory fallback directly in the FactoryManager as the Application may...

Put the factory fallback directly in the FactoryManager as the Application may not have been instantiated

(cherry picked from commit cfb4b342)
parent 496e4071
No related branches found
No related tags found
1 merge request!782Backport to 3.3.x
package org.videolan.libvlc;
import android.util.Log;
import org.videolan.libvlc.interfaces.IComponentFactory;
import org.videolan.libvlc.interfaces.ILibVLCFactory;
import org.videolan.libvlc.interfaces.IMediaFactory;
import java.util.HashMap;
import java.util.Map;
......@@ -13,6 +17,14 @@ public class FactoryManager {
}
public static IComponentFactory getFactory(String factoryId) {
return factories.get(factoryId);
IComponentFactory factory = factories.get(factoryId);
// Fallback in case the factories have not been populated. It happens in some occasions when the custom Application class has not been instantiated (probably due to the app being in a backup routine)
if (factory == null) {
Log.e("FactoryManager", "Factory doesn't exist. Falling back to hard coded one");
if (factoryId.equals(IMediaFactory.factoryId)) registerFactory(IMediaFactory.factoryId, new MediaFactory());
if (factoryId.equals(ILibVLCFactory.factoryId)) registerFactory(ILibVLCFactory.factoryId, new LibVLCFactory());
factory = factories.get(factoryId);
}
return factory;
}
}
......@@ -10,9 +10,6 @@ import org.videolan.libvlc.interfaces.IMediaFactory;
import java.io.FileDescriptor;
public class MediaFactory implements IMediaFactory {
static {
FactoryManager.registerFactory(IMediaFactory.factoryId, new MediaFactory());
}
@Override
public IMedia getFromLocalPath(ILibVLC ILibVLC, String path) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment