Embedding VLC player in WInform Application in .Net Core. Core.Intialize() Giving Exception - c#

I am trying to Embed VLc in Winform Application on .net core 3.1 framework. Packages installed are
**
LibVLCSharp 3.6.1
LibVLCSharp.WinForms 3.6.1
**
private void PlayerForm_Load(object sender, EventArgs e)
{
var url = typeof(LibVLC).Assembly.Location;
Core.Initialize();
using(var libvlc = new LibVLC())
using (var mediaPlayer = new MediaPlayer(libvlc))
{
var uri = new Uri("C:\\Active Projects\\ScreenPlayerWeb\\ScreenPlayerWeb\\wwwroot\\Videos\\VID_20190621_112556.3gp");
using var media = new Media(libvlc, uri);
mediaPlayer.Fullscreen = true;
mediaPlayer.Play();
}
}
Core.Initialize() Giving Exception
**
LibVLCSharp.Shared.VLCException: 'Failed to load required native libraries.
Have you installed the latest LibVLC package from nuget for your target platform?
Search paths include C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlccore.dll; C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlc.dll,C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc\win-x64\libvlccore.dll; C:\Active Projects\ScreenPlayerClient\ScreenPlayerClient\ScreenPlayerClient\bin\Debug\netcoreapp3.1\libvlc.dll,'
**
Its searching for wrong file in my devug/netcore3.1 folder there is no file as libvlc.dll ...
files avaialble are libvlcsharp.dll, libvlcsharp.winforms.dll and vlc.dotnet.core.dll.
There are answers on stack overflow but most of these are more than 5 years old so cant be referenced to updated versions of LIbVlc and .Net
Help will be highly appriciated.

The package doesn't include the actual 'libvlc' as you might expect, its only initialization code in the LibVLCSharp. Ensure you installed the VideoLAN.LibVLC.[YourPlatform] package in your target project. Or download it manually and point towards the folder:
Core.Initialize(#"C:\yourpath\libvlc\win-x64");
var libvlc = new LibVLC();
// Make VideoView control
VideoView vv = new VideoView();
vv.MediaPlayer = new MediaPlayer(libvlc);
vv.Dock = DockStyle.Fill;
// Add it to the form
Controls.Add(vv);
var uri = new Uri(#"C:\Video.mp4");
// Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
var media = new Media(libvlc, uri, ":input-repeat=65535");
vv.MediaPlayer.Play(media);
//Set fullscreen
this.FormBorderStyle = FormBorderStyle.None;
this.Size = Screen.PrimaryScreen.Bounds.Size;
this.Location = Screen.PrimaryScreen.Bounds.Location;

Related

How to change android manifest permission for connect to another app in unity

I am new to unity and want to connect a page of application in market or any other apps, so I used some script in other threads but it didn't work so I think it need some change in Android manifest too for script to work.
my script is like this and a button in game run it's function.
bool fail = false;
string bundleId = "bazaar://details?id=" + "cab.snapp.passenger"; // your target bundle id
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{ //open app in store
Application.OpenURL("https://google.com");
}
else //open the app
ca.Call("startActivity", launchIntent);
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
I changed string bundle but it didn't work and look forward beside solution for this problem if there is any way to use intent with Uri for openning another app in unity c#.

Selenium cannot load specific created profile in firefox driver

I am trying to get a specific firefox profile which I created beforehand.
However when i execute the below code i get an exception saying that the profile doesn't exist.
var profileManager = new FirefoxProfileManager();
var profile = profileManager.GetProfile("profile");
var options = new FirefoxOptions { Profile = profile };
profile.SetPreference("webdriver.firefox.profile", "profile");
var driver = new FirefoxDriver(#"C:\Users\danza\source\repos\InstaManager\", options);
So after investigating this problem, I found out that it was mainly a package version issue. I was using Selenium.WebDriver alpha version nuget package. The solution was to downgrade to a stable version of this nuget package.
Alternatively you can use it so
var options = new FirefoxOptions();
options.Profile = new FirefoxProfile("C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\profilename");
var webDriver = new FirefoxDriver(webdriverPath, options)
The firefox profiles are stored in the path AppData\Roaming\Mozilla\Firefox\Profiles

How do you launch a web authentication window within Unity for a UWP app?

I'm trying to use the Twitter Service from the UWPCommunityToolkit, which I have running as a standalone UWP (Universal Windows Platform) app, but when I import it into Unity (2017.2.0f3) as a library, it doesn't open the authentication window.
This is what shows up on the working standalone UWP app:
When in unity, it seems to go through the setup code, but not run this line properly:
var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);
https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.Services/Services/Twitter/TwitterDataProvider.cs#L293
It just returns WebAuthenticationStatus.UserCancel, whereas on the standalone UWP, it'd return WebAuthenticationStatus.Success. Note, it also returns WebAuthenticationStatus.UserCancel on the standalone UWP app when the user clicks the close button on the pop up.
Is it possible to run WebAuthenticationBroker.AuthenticateAsync (https://learn.microsoft.com/en-us/windows/uwp/security/web-authentication-broker) in Unity? Are there any other ways to do web authentication on the Windows platform using Unity?
I've also tried TwitterKit, but unfortunately, it doesn't have support for Windows UWP (only iOS and Android).
Thanks!
LINQ to Twitter supports UWP. It has a UniversalAuthorizer that works like this:
private async void TweetButton_Click(object sender, RoutedEventArgs e)
{
var authorizer = new UniversalAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = "",
ConsumerSecret = ""
}
};
await authorizer.AuthorizeAsync();
var ctx = new TwitterContext(authorizer);
string userInput = tweetText.Text;
Status tweet = await ctx.TweetAsync(userInput);
ResponseTextBlock.Text = tweet.Text;
await new MessageDialog("You Tweeted: " + tweet.Text, "Success!").ShowAsync();
}
Check out the Samples folder for a complete listing: https://github.com/JoeMayo/LinqToTwitter

Hows the following code run in autocad?

Hello this is my code and i don't know how to run and get output of this code. Please suggest me the answer for this.And I want to create command for autocad using this code so suggest me according to this requirement.
using System;
using System.IO;
using System.Globalization;
using UDC;
using AutoCAD = Autodesk.AutoCAD.Interop;
namespace AutoCADtoPDF
{
class Program
{
static void PrintAutoCADtoPDF(string AutoCADFilePath)
{
//Create a UDC object and get its interfaces
IUDC objUDC = new APIWrapper();
IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter");
IProfile Profile = Printer.Profile;
//Use Universal Document Converter API to change settings of converterd drawing
//Load profile located in folder "%APPDATA%\UDC Profiles".
//Value of %APPDATA% variable should be received using Environment.GetFolderPath method.
//Or you can move default profiles into a folder you prefer.
string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string ProfilePath = Path.Combine(AppDataPath, #"UDC Profiles\Drawing to PDF.xml");
Profile.Load(ProfilePath);
Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED;
Profile.OutputLocation.FolderPath = #"c:\UDC Output Files";
Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER;
AutoCAD.AcadApplication App = new AutoCAD.AcadApplicationClass();
double Version = double.Parse(App.Version.Substring(0, 4), new CultureInfo("en-US"));
//Open drawing from file
Object ReadOnly = false;
Object Password = Type.Missing;
AutoCAD.AcadDocument Doc = App.Documents.Open(AutoCADFilePath, ReadOnly, Password);
//AutoCAD.Common.AcadPaperSpace ActiveSpace;
AutoCAD.Common.AcadLayout Layout;
//Change AutoCAD preferences for scaling the drawing to page
if (Doc.ActiveSpace == 0)
Layout = Doc.PaperSpace.Layout;
else
Layout = Doc.ModelSpace.Layout;
Layout.PlotType = AutoCAD.Common.AcPlotType.acExtents;
Layout.UseStandardScale = true;
Layout.StandardScale = AutoCAD.Common.AcPlotScale.acScaleToFit;
Layout.CenterPlot = true;
Object nBACKGROUNDPLOT = 0, nFILEDIA = 0, nCMDDIA = 0;
if (Version >= 16.1f)
{
nBACKGROUNDPLOT = Doc.GetVariable("BACKGROUNDPLOT");
nFILEDIA = Doc.GetVariable("FILEDIA");
nCMDDIA = Doc.GetVariable("CMDDIA");
Object xNull = 0;
Doc.SetVariable("BACKGROUNDPLOT", xNull);
Doc.SetVariable("FILEDIA", xNull);
Doc.SetVariable("CMDDIA", xNull);
}
Doc.Plot.QuietErrorMode = true;
//Plot the drawing
Doc.Plot.PlotToDevice("Universal Document Converter");
if (Version >= 16.1f)
{
//Restore AutoCAD default preferences
Doc.SetVariable("BACKGROUNDPLOT", nBACKGROUNDPLOT);
Doc.SetVariable("FILEDIA", nFILEDIA);
Doc.SetVariable("CMDDIA", nCMDDIA);
}
//Close drawing
Object SaveChanges = false;
Doc.Close(SaveChanges, Type.Missing);
//Close Autodesk AutoCAD
App.Quit();
}
static void Main(string[] args)
{
string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.dwg");
PrintAutoCADtoPDF(TestFilePath);
}
}
}
Did you read the comments in the original source ?
This code is a example of using a third part application name Universal Document Converter (UDC) to build a standalone application (exe) to print the active space of a dwg file into a pdf file.
It requires the UDC software to be installed.
It cannot be transformed into an AutoCAD plugin (dll with CommandMethod).
You certainly can get more informations about this with the UDC Support.
You will not learn .NET and AutoCAD API by copying codes found on the web that you do not understand and asking someone here or elsewhere to modify them to suit your needs.
first: add a using to the runtime.
using Autodesk.AutoCAD.Runtime;
next: Add an attribute to your method.
[CommandMethod("YOURCOMMANDNAMEINAUTOCAD")]
Last: Your class and method need to be public, for AutoCAD to see them.
Update: (Very last): your Method cannot take parameters.

Directory Not Found Exception or FileNotFoundException on VLC.DotNet

Using the VLC library provided by Vlc.DotNet, I have tried to implement it in a simple WPF.
I copied exactly the code from the repository, and got the NuGet online, but can't seem to make it work. I get a Directory Not Found exception straight from the load of the file on the disk.
Here is my code:
public MainWindow()
{
InitializeComponent();
VLCControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
}
private void OnVlcControlNeedsLibDirectory(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
{
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
if (currentDirectory == null)
return;
if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, #"..\..\..\lib\x86\"));
else
e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, #"..\..\..\lib\x64\"));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var d = new Microsoft.Win32.OpenFileDialog();
d.Multiselect = false;
if (d.ShowDialog() == true)
{
Uri src = new Uri(d.FileName);
VLCControl.MediaPlayer.Play(src); //Exception here
}
}
VLCControl being the VLC control in the xaml.
By changing the VlcLibDirectory with another path where I put the libraries (for example the root of application), I get this StackTrace :
at Vlc.DotNet.Core.Interops.VlcInteropsManager..ctor(DirectoryInfo dynamicLinkLibrariesPath)
at Vlc.DotNet.Core.Interops.VlcManager..ctor(DirectoryInfo dynamicLinkLibrariesPath)
at Vlc.DotNet.Core.Interops.VlcManager.GetInstance(DirectoryInfo dynamicLinkLibrariesPath)
at Vlc.DotNet.Core.VlcMediaPlayer..ctor(DirectoryInfo vlcLibDirectory)
at Vlc.DotNet.Forms.VlcControl.EndInit()
at Vlc.DotNet.Forms.VlcControl.Play(Uri uri, String[] options)
at VLCTest.MainWindow.Button_Click(Object sender, RoutedEventArgs e) in c:\Users\ME\Documents\Visual Studio 2013\Projects\VLCTest\VLCTest\MainWindow.xaml.cs:ligne 56
The code becomes :
if(AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
else
e.VlcLibDirectory = new DirectoryInfo(currentDirectory);
Thank you for your help.
The problem is definitely with your library path, though you have to debug the problem yourself in order to find the exact discrepancy between provided path and actual path.
The misunderstanding may be, which libraries are missing. You do have the Vlc.DotNet.Core.Interops.dll but your are missing the nativ libraries behind. This is the reason, why the exception occurs inside Vlc.DotNet.Core.Interops.dll when it tries to load the actual libraries.
The OnVlcControlNeedsLibDirectory function is called inside VLCControl.MediaPlayer.Play(src);, so the Path from OpenFileDialog has nothing to do with the problem.
Steps I taken to reproduce / fix:
Downloaded your project
Tested / Debugged
Exception occurred as you describe
Downloaded the libraries from Vlc.DotNet repository
Changed the paths to absolute values
Tested / Debugged again
Successfully played a music file
Another exception occured on closing (different story alltogether)
My folder layout:
Solution path:
D:\Programmierung\VLCTest-VAlphaTesting\VLCTest-VAlphaTesting\
Actual Assembly location on execute
D:\Programmierung\VLCTest-VAlphaTesting\VLCTest-VAlphaTesting\VLCTest\bin\Debug
ProcessorArchitecture: x86
Library Path:
D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x86
Contents of library path:
plugins (folder)
.keep (file)
libvlc.dll (file)
libvlccore.dll (file)
For testing purposes I hardcoded the library path - you may want to do that as well
if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
e.VlcLibDirectory = new DirectoryInfo(#"D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x86");
else
e.VlcLibDirectory = new DirectoryInfo(#"D:\Programmierung\Vlc.DotNet-master\Vlc.DotNet-master\lib\x64");

Categories