Windows Forms OpenFileDialog and LibVLC plugins dll entry point error - winforms

I'm using libvlc library. And it works well when I play the video file, that I have chosen in openFileDialog previously. But my goal is streaming video from webcam and previewing it.
I made libvlc show webcam video on the screen, but when i commented out the openFileDialog.Show() line (that I don't need anymore), "Entry point couldn't be found in the library" error dialogs started poping out for every libvlc plugin (that is basicaly a .dll file).
private void btPlay_Click(object sender, EventArgs e)
{
/*
if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
* */
CleanUp();
string pluginPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
string[] args = new string[]{
"--no-qt-error-dialogs",
"--ignore-config",
"--quiet",
"--plugin-path=" + pluginPath
};
//LibVlc initialization, that is where ERORR OCCURES
vlcInst = new VlcInstance(args);
/* Input media settings */
//VlcMedia media = new VlcMedia(vlcInst, openFileDialog1.FileName);
VlcMedia media = new VlcMedia(vlcInst, "dshow://");
LibVlc.libvlc_media_add_option(media.handle, "dshow-vdev=USB2.0 UVC VGA WebCam");
LibVlc.libvlc_media_add_option(media.handle, "dshow-adev=none");
/* Output media settings */
string[] outputOptions = new string[] {
"sout=#duplicate{",
"dst=",
"display",
",",
"dst=",
"'",
"transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}",
":http{mux=ffmpeg{mux=flv},dst=:666/}",
"'",
"}"
};
LibVlc.libvlc_media_add_option(media.handle, String.Concat(outputOptions));
streamer = new VlcStreamer(media);
media.Dispose();
streamer.Drawable = mediaPanel.Handle;
streamer.Play();
}
private void CleanUp()
{
if (streamer != null)
{
streamer.Stop();
streamer.Dispose();
}
}
I can't see any relations between OpenFileDialog and libvlc plugins.
What can cause such a problem?
EDITED:
After I skip all error dialogs, program continues working.

When I was using VLC player, it made duplicates of the plugins in "plugin" folder. In my app I used those plugins and was getting errors. After I downloaded and unpacked new instance of the player, I discovered that there were no duplicates of the plugins, so I made a conclusion that the player makes copies of plugins when you launch it first time (didn't test it).
When I replaced my plugin folder with new one, all the errors were gone.

Related

Image always missing in the received message while sharing an image in Codename One

I am generating an image that is saved in FileSytemStorage.getAppHomePath() dir. I now need to share it via Email, SMS ... That's why I am using the following code (based on Codename One documentation) in my action method :
long time = new Date().getTime();
String fullOutputPath = FileSystemStorage.getInstance().getAppHomePath()
+ "Montage_" + Long.toString(time) + ".png";
// Save the image with the ImageIO class
try (OutputStream os = FileSystemStorage.getInstance().openOutputStream(fullOutputPath)){
ImageIO.getImageIO().save(montage.getMontageImage(), os, ImageIO.FORMAT_PNG, 1.0f);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Enable image sharing (outside the try/catch so that the outputstream in closed for sure)
if (FileSystemStorage.getInstance().exists(fullOutputPath)) {
Dialog.show("Saved", "Photo collage saved to " + fullOutputPath
+ " (file size = " + FileSystemStorage.getInstance().getLength(fullOutputPath) +" B)", "OK", null);
//Photo collage saved to file://home/Montage_14669... .png (file size = 50387B)
findValidateMontageShareButton3().setImageToShare(fullOutputPath, "image/png");
// Null pointer exception
So in that way I get a NPE and if I don't test if the file does exist there is no NPE but the image is still missing (both in the simulator and on the device).
The stack trace is as follows :
java.lang.NullPointerException
at userclasses.StateMachine.onPage3_ValidateMontageShareButton3Action(StateMachine.java:852)
at generated.StateMachineBase.handleComponentAction(StateMachineBase.java:757)
at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2835)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:459)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:362)
at com.codename1.ui.Button.fireActionEvent(Button.java:411)
at com.codename1.ui.Button.released(Button.java:442)
at com.codename1.ui.Button.pointerReleased(Button.java:530)
at com.codename1.ui.Form.pointerReleased(Form.java:2627)
at com.codename1.ui.Form.pointerReleased(Form.java:2563)
at com.codename1.ui.Component.pointerReleased(Component.java:3158)
at com.codename1.ui.Display.handleEvent(Display.java:2025)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1067)
at com.codename1.ui.Display.mainEDTLoop(Display.java:996)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
It looks that the file my app is generating is not accesible to the sharing app. Do I have to add any extra permission as advised here for Android ?
Please note : I don't know if it is related to this problem but I cannot access to Codename One Settings menu from Eclipse anymore (maybe since upgrade to CN1 lib v 115)
Any help appreciated,
Cheers
So here is part of the answer which works in the simulator (ie the image appears in the fake email client => see image below).
So it appears that the share button cannot be set up in the action method (ie the method that is triggered when the user click on the share button). It has to be set up previously.
Consequently, in the beforeShow method my code reads as follows :`
FontImage.setMaterialIcon(findValidateMontageShareButton3(), FontImage.MATERIAL_CHECK_CIRCLE);
final long time = new Date().getTime();
// We generate the montage filename JPG otherwise it cannot be sent
montage.setMontageFullPath(FileSystemStorage.getInstance().getAppHomePath()
+ "Montage_" + Long.toString(time) + ".jpg");
// We assign the montage filename to the share button BEFORE we can click the button (otherwise the
// filename cannot be taken into account)
findValidateMontageShareButton3(f).setImageToShare(
montage.getMontageFullPath(), "image/jpeg");
Then in the onAction method related to the share button the code reads :
// Save the image with the ImageIO class
// We wait until the file is completely written to continue
Display.getInstance().invokeAndBlock(new Runnable() {
#Override
public void run() {
try (OutputStream os = FileSystemStorage.getInstance().openOutputStream(montage.getMontageFullPath())){
ImageIO.getImageIO().save(montage.getMontageImage(), os, ImageIO.FORMAT_JPEG, 1);
} catch (IOException e) {
Dialog.show("Erreur", "Impossible de sauvegarder le montage! Merci de vérifier l'espace disque disponible.", null, "OK" );
}
}
});
I tested it and it worked on the simulator but not on the device. Either with a png or a jpeg file, the file cannot be attached to the SMS or email (Android error message "abnormal file, can't attached file").
However if I do it a second time, then the file can be attached. So now the image is not missing but it cannot be attached (the first time) which is still embarrassing.

zipme implementation in codenameone

I want to apply unzipping the file using zipme cn1 library (codenameone library). Is there any examples on how to do it? Can anyone give me the starting point? So far I have tried the following code but I am not sure where to keep dataName.zip file in the project and the folder to keep all the files after unzipping.
#Override
protected void beforeMain(Form f) {
net.sf.zipme.ZipEntry dataZE;
InputStream isData = getClass().getResourceAsStream("/" + "dataName" + ".zip");
StringBuffer sbData = new StringBuffer();
ZipInputStream dataZIS = new ZipInputStream(isData);
try {
while ((dataZE = dataZIS.getNextEntry()) != null) {
//how to extract the zip file in a separate folder...
dataZIS.closeEntry();
}
} catch (IOException ex) {
System.out.println("zip exception");
}
}
The above code gives following error:
cannot find symbol
InputStream isData = getClass().getResourceAsStream("");
symbol: method getResourceAsStream(String)
One more thing, why cant I use the following to get the zip file as in core java
ZipInputStream zis = new ZipInputStream(new FileInputStream("C:\\abc.zip"));
// it gives "FileInputStream: cannot find symbol"
How can I extract the zip file in a separate folder?
You should use Display.getInstance().getResourceAsStream().
FileInputStream isn't supported in Codename One which uses FileSystemStorage. The FileInputStream and File API's assume many things about the underlying OS that aren't always true.

JFormDesigner Runtime Library Doesn't Load Custom Code

I've been using JFormDesigner with the runtime library to create dialogs directly from the .jfd files at runtime (I can't change this; not my decision). My problem is that the runtime library doesn't seem to preserve any custom code generation listed in the .jfd file. For example, if I have a simple panel, with the background set to red, and a post-initialization command to set the background to green, the runtime library will yield a red background, while directly loading the generated .java file will properly set the background to green.
Here's a code sample of what I'm doing:
public class EntryPoint
{
public static void main( String[] args )
{
// Load .jfd file. Shows red background (incorrect).
String form = "testProject/entry/TestDialog.jfd";
new EntryPoint(form);
// Load .java file. Shows green background (correct).
JFrame frame = new JFrame();
TestDialog test = new TestDialog( frame );
test.setVisible( true );
}
EntryPoint( String form )
{
try
{
// Example loading
// see http://www.formdev.com/jformdesigner/doc/runtime-library/
FormModel formModel = FormLoader.load( form );
FormCreator formCreator = new FormCreator(formModel);
formCreator.setTarget(this);
JDialog dialog = formCreator.createDialog(null);
dialog.setModal(true);
dialog.pack();
dialog.show();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
I took a quick look at the documentation, but to no avail. I have an e-mail sent to JFD's support team, and will update the question if I get any response. I'm looking through the runtime library code now (it's open source), but was curious if anyone had any info on it before I go too far down the rabbit hole. Thanks.
Support replied; feature not currently supported (as of version 5.2).

Sharepoint 2010 Upload file using Silverlight 4.0

I am trying to do a file upload from Silverlight(Client Object Model) to Sharepoint 2010 library.. Please see the code below..
try{
context = new ClientContext("http://deepu-pc/");
web = context.Web;
context.Load(web);
OpenFileDialog oFileDialog = new OpenFileDialog();
oFileDialog.FilterIndex = 1;
oFileDialog.Multiselect = false;
if (oFileDialog.ShowDialog().Value == true)
{
var localFile = new FileCreationInformation();
localFile.Content = System.IO.File.ReadAllBytes(oFileDialog.File.FullName);
localFile.Url = System.IO.Path.GetFileName(oFileDialog.File.Name);
List docs = web.Lists.GetByTitle("Gallery");
context.Load(docs);
File file = docs.RootFolder.Files.Add(localFile);
context.Load(file);
context.ExecuteQueryAsync(OnSiteLoadSuccess, OnSiteLoadFailure);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
But I am getting the following error
System.Security.SecurityException: File operation not permitted. Access to path '' is denied.
at System.IO.FileSecurityState.EnsureState()
at System.IO.FileSystemInfo.get_FullName()
at ImageUploadSilverlight.MainPage.FileUpload_Click(Object sender, RoutedEventArgs e)
Any help would be appreciated
Thanks
Deepu
Silverlight runs with very restricted access to the client user's filesystem. When using an open-file dialog, you can get the name of the selected file within its parent folder, the length of the file, and a stream from which to read the data in the file, but not much more than that. You can't read the full path of the file selected, and you are getting the exception because you are attempting to do precisely that.
If you want to read the entire content of the file into a byte array, you'll have to replace the line
localFile.Content = System.IO.File.ReadAllBytes(oFileDialog.File.FullName);
with something like
localFile.content = ReadFully(oFileDialog.File.OpenRead());
The ReadFully method reads the entire content of a stream into a byte array. It's not a standard Silverlight method; instead it
is taken from this answer. (I gave this method a quick test on Silverlight, and it appears to work.)

silverlight 4, dynamically loading xap modules

I know that it is possible to load xap modules dynamically using Prism or MEF framework. However, I'd like not to use those frameworks; instead load my xap files manually. So, I created the following class (adapted from internet):
public class XapLoader
{
public event XapLoadedEventHandler Completed;
private string _xapName;
public XapLoader(string xapName)
{
if (string.IsNullOrWhiteSpace(xapName))
throw new ArgumentException("Invalid module name!");
else
_xapName = xapName;
}
public void Begin()
{
Uri uri = new Uri(_xapName, UriKind.Relative);
if (uri != null)
{
WebClient wc = new WebClient();
wc.OpenReadCompleted += onXapLoadingResponse;
wc.OpenReadAsync(uri);
}
}
private void onXapLoadingResponse(object sender, OpenReadCompletedEventArgs e)
{
if ((e.Error == null) && (e.Cancelled == false))
initXap(e.Result);
if (Completed != null)
{
XapLoadedEventArgs args = new XapLoadedEventArgs();
args.Error = e.Error;
args.Cancelled = e.Cancelled;
Completed(this, args);
}
}
private void initXap(Stream stream)
{
string appManifest = new StreamReader(Application.GetResourceStream(
new StreamResourceInfo(stream, null), new Uri("AppManifest.xaml",
UriKind.Relative)).Stream).ReadToEnd();
XElement deploy = XDocument.Parse(appManifest).Root;
List<XElement> parts = (from assemblyParts in deploy.Elements().Elements()
select assemblyParts).ToList();
foreach (XElement xe in parts)
{
string source = xe.Attribute("Source").Value;
AssemblyPart asmPart = new AssemblyPart();
StreamResourceInfo streamInfo = Application.GetResourceStream(
new StreamResourceInfo(stream, "application/binary"),
new Uri(source, UriKind.Relative));
asmPart.Load(streamInfo.Stream);
}
}
}
public delegate void XapLoadedEventHandler(object sender, XapLoadedEventArgs e);
public class XapLoadedEventArgs : EventArgs
{
public Exception Error { get; set; }
public bool Cancelled { get; set; }
}
The above code works fine; I can load any xap the following way:
XapLoader xapLoader = new XapLoader("Sales.xap");
xapLoader.Completed += new XapLoadedEventHandler(xapLoader_Completed);
xapLoader.Begin();
Now, I have a UserControl called InvoiceView in the Sales.xap project, so I would like to instantiate the class. In the current project (Main.xap) I added reference to Sales.xap project, however, since I load it manually I set "Copy Local = False". But when executed, the following code throws TypeLoadException:
Sales.InvoiceView view = new Sales.InvoiceView();
It seems the code can't find InvoiceView class. But I checked that XapLoader's initXap() method was successfully executed. So why the code can't find InvoiceView class? Can someone help me with this problem?
This is based on the asker's self-answer below, rather than the question.
If you delete a project/module the output DLLs/XAP files do hang around. If you click the "show all files" button you will see some these left-over output files in your clientbin, bin and obj folders of related projects.
You can delete them individually from the project, or, when in doubt, search for all BIN and OBJ (e.g. using desktop explorer) and delete all those folders. The BIN/CLIENTBIN/OBJ folders will be recreated when needed (this the job that the "clean" option in Visual Studio should have done!)
Hope this helps.
Ok, I found the cause. The above code works. After creating a new silverlight project (Sales.xap) I happened to compile my solution once. Then I deleted App class in the Sales.xap and renamed default MainPage class to SalesView. However, no matter how many times I compile my solution, Visual Studio's development web server was loading the first version of Sales.xap (where from?), so my code couldn't find SalesView. In my host Asp.Net project I set development server's port to a different port number, and the problem gone. So the problem was with Visual Studio's development server. Apparently it is keeping compiled xap files in some temporary folder, and doesn't always update those xap files when source code changed.
What I do to avoid such problems when executing freshly compiled Silverlight is clear the browser cache, chrome even has a clear silverlight cache ;)
this XAP Cache phenomena is often due to the visual studio embedded web server (ASP.NET Development Server).
Just stop the occurence of this server and the cache will be cleared.
Start again your project and the latest build of your xap is called.

Resources