Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
0
Answer
to enable audio controls in cefsharp Browser
Shruthi Kadam
4y
1.7k
1
Reply
Hello Sir,
I have changed default web broswer to cefsharp chromium web browser but the thing is chrome is not supporting audio with in my browser when i upload html pages . I have tried this
using
System;
using
System.Windows;
using
System.Windows.Media.Imaging;
using
Syncfusion.Windows.Shared;
using
Microsoft.Win32.SafeHandles;
using
VISL.Entity;
using
VISL.Common;
using
VISL.BoxedApp;
using
VISL.DAL;
using
System.IO;
using
System.Runtime.InteropServices;
using
System.Windows.Interop;
using
VISL.Subjects;
using
System.Windows.Input;
using
System.Collections.Generic;
using
System.Text.RegularExpressions;
using
System.Windows.Controls;
using
System.Windows.Navigation;
using
System.Reflection;
using
System.IO.Compression;
using
CefSharp;
using
CefSharp.Wpf;
namespace
VISL.Subjects
{
/// <summary>
/// Interaction logic for CefTest.xaml
/// </summary>
public
partial
class
CefTest : Window
{
Window prevWindow;
ContentMasterDTO content;
string
tempDirPath =
string
.Empty;
//DisplayRestriction displayRestriction = new DisplayRestriction();
VideoPlayerDAL videoPlayerDAL =
new
VideoPlayerDAL();
PreviousSelection prevSelection;
#region Print Screen and Other Restrictions
[DllImport(
"user32.dll"
)]
static
extern
bool
SetWindowDisplayAffinity(IntPtr hwnd, DisplayAffinity affinity);
[DllImport(
"user32.dll"
)]
static
extern
IntPtr GetActiveWindow();
#endregion
public
CefTest()
{
InitializeComponent();
this
.Icon =
new
BitmapImage(
new
Uri(CommonProperties.AppIcon));
this
.WindowState = WindowState.Maximized;
this
.WindowState = System.Windows.WindowState.Maximized;
this
.WindowStyle = WindowStyle.SingleBorderWindow;
}
public
CefTest(ContentMasterDTO obj) :
this
()
{
content = obj;
}
public
CefTest(ContentMasterDTO obj, Window _prevWindow) :
this
()
{
content = obj;
prevWindow = _prevWindow;
}
public
CefTest(ContentMasterDTO obj, PreviousSelection prev) :
this
()
{
content = obj;
prevSelection = prev;
}
private
void
Window_Loaded(
object
sender, EventArgs e)
{
if
(prevWindow !=
null
)
{
prevWindow.Hide();
}
//string htmlString = System.IO.File.ReadAllText(CommonProperties.ExecutablePath + @"\Contents\Agriculture\Index.htm");
//htmlString = ImageDisplay(htmlString);
//webBrowser.NavigateToString(htmlString);
//string path = @"E:\VISL\VISL\bin\x86\Debug\Contents\Agriculture\Index.html";
//webBrowser.Navigate(path);
//webBrowser.Navigated += new NavigatedEventHandler(webBrowser_Navigated);
//InitHTMLPlayer();
//var hwnd = new WindowInteropHelper(this).Handle;
//SetWindowDisplayAffinity(hwnd, DisplayAffinity.Monitor);
}
public
void
InitHTMLPlayer()
{
try
{
#region Display HTML
BoxedAppSDK.NativeMethods.BoxedAppSDK_SetContext(
"29c3c554-6033-4eb5-95fe-cadc013c229e"
);
// <-- set the key here
BoxedAppSDK.NativeMethods.BoxedAppSDK_Init();
//content.ContentPath = @"E:\Visual studio projects\VISL\bin\Debug\Contents\MicroOrganism_#8EEIOP7#V1W07I.zip.Pro";
//EncryptionKeyDTO obj = videoPlayerDAL.GetEncryptionKey(11);
EncryptionKeyDTO obj = videoPlayerDAL.GetEncryptionKey(content.IdEncryptionKey);
CommonUtils.Key = Convert.FromBase64String(obj.EncryptionKEY);
CommonUtils.IV = Convert.FromBase64String(obj.EncryptionIV);
using
(SafeFileHandle fileHandle =
new
SafeFileHandle(
BoxedAppSDK.NativeMethods.BoxedAppSDK_CreateVirtualFileBasedOnIStream(
@
"virtualZipFile.zip"
,
// name of the pseudo file
BoxedAppSDK.NativeMethods.EFileAccess.GenericWrite,
BoxedAppSDK.NativeMethods.EFileShare.Read,
IntPtr.Zero,
BoxedAppSDK.NativeMethods.ECreationDisposition.New,
BoxedAppSDK.NativeMethods.EFileAttributes.Normal,
IntPtr.Zero,
new
VirtualFileStream(content.ContentPath)
),
true
)
)
{
// We use "using" to close the allocated handle
// The virtual file will still exist
}
//// Load a html in HTMLPlayer.
tempDirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
"\\OfflineHtml"
;
//tempDirPath = "D:\"
//tempDirPath = @"C:\OfflineHtml";
if
(!Directory.Exists(tempDirPath))
Directory.CreateDirectory(tempDirPath);
else
DeleteDirectory(tempDirPath);
Directory.CreateDirectory(tempDirPath);
ReadWriteStream();
string
zipPath = tempDirPath +
"\\tempVirtualFile.zip"
;
System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, tempDirPath);
File.Delete(zipPath);
foreach
(
string
d
in
Directory.GetDirectories(tempDirPath))
{
tempDirPath = d +
"\\index.html"
;
}
//webBrowser.Navigate(new Uri(tempDirPath, UriKind.RelativeOrAbsolute));
web.Address = tempDirPath;
// webBrowser.URL = tempDirPath;
// webBrowser.Source = new Uri(tempDirPath);
//tempDirPath = System.IO.Path.GetTempPath() + "OfflineHtml";
//if (!Directory.Exists(tempDirPath))
// Directory.CreateDirectory(tempDirPath);
//Stream a = File.Open(@"virtualZipFile.html", FileMode.Open);
//Stream b = File.Open(tempDirPath + "\\tempVirtualFile.html", FileMode.Create);
//ReadWriteStream(a, b);
//tempDirPath = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName;
//tempDirPath = tempDirPath + "\\virtualZipFile.html";
//Stream source = File.OpenRead(tempDirPath);
//webBrowser.NavigateToStream(source);
//webBrowser.Navigated += new NavigatedEventHandler(webBrowser_Navigated);
#endregion
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private
void
ReadWriteStream()
//Stream readStream, Stream writeStream
{
Stream readStream = File.Open(@
"virtualZipFile.zip"
, FileMode.Open);
Stream writeStream = File.Open(tempDirPath +
"\\tempVirtualFile.zip"
, FileMode.Create);
int
Length = 1024 * 1024;
//Convert.ToInt32(readStream.Length / 16);
Byte[] buffer =
new
Byte[1024 * 1024];
int
bytesRead = 1;
//readStream.Read(buffer, 0, Length);
// write the required bytes
while
(bytesRead > 0)
{
bytesRead = readStream.Read(buffer, 0, Length);
writeStream.Write(buffer, 0, bytesRead);
}
readStream.Close();
writeStream.Close();
readStream.Dispose();
writeStream.Dispose();
GC.Collect();
}
private
void
DeleteDirectory(
string
path)
{
try
{
if
(Directory.Exists(path))
{
string
[] fileList = Directory.GetFiles(path);
//Delete all files from the Directory
foreach
(
string
file
in
fileList)
//Directory.GetFiles(path))
{
FileAttributes attr = File.GetAttributes(file);
//if (attr == FileAttributes.ReadOnly)
// File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
//Delete all child Directories
foreach
(
string
directory
in
Directory.GetDirectories(path))
{
DeleteDirectory(directory);
}
//Delete a Directory
Directory.Delete(path,
true
);
}
}
catch
(Exception ex)
{
Console.Write(ex.Message);
}
}
private
void
webBrowser_Navigated(
object
sender, NavigationEventArgs e)
{
//SetSilent(webBrowser, true); // make it silent
}
public
string
ImageDisplay(
string
htmlString)
{
string
part1 =
" <img src="
+
"\""
+ CommonProperties.ExecutablePath +
"\\App_Images\\"
;
string
part2 =
"\""
+
" />"
;
string
pattern1 = @
"<(img)\b[^>]*>"
;
string
pattern2 = @
"</(img)\b[^>]*>"
;
GetImagesInHTMLString(htmlString, pattern1).ForEach(i =>
{
htmlString = htmlString.Replace(i, part1);
});
GetImagesInHTMLString(htmlString, pattern2).ForEach(i =>
{
htmlString = htmlString.Replace(i, part2);
});
return
htmlString;
}
private
List<
string
> GetImagesInHTMLString(
string
htmlString,
string
pattern)
{
List<
string
> images =
new
List<
string
>();
Regex rgx =
new
Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(htmlString);
for
(
int
i = 0, l = matches.Count; i < l; i++)
{
images.Add(matches[i].Value);
}
return
images;
}
public
static
void
SetSilent(WebBrowser browser,
bool
silent)
{
if
(browser ==
null
)
throw
new
ArgumentNullException(
"browser"
);
// get an IWebBrowser2 from the document
IOleServiceProvider sp = browser.Document
as
IOleServiceProvider;
if
(sp !=
null
)
{
Guid IID_IWebBrowserApp =
new
Guid(
"0002DF05-0000-0000-C000-000000000046"
);
Guid IID_IWebBrowser2 =
new
Guid(
"D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"
);
object
webBrowser;
sp.QueryService(
ref
IID_IWebBrowserApp,
ref
IID_IWebBrowser2,
out
webBrowser);
if
(webBrowser !=
null
)
{
webBrowser.GetType().InvokeMember(
"Silent"
, BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty,
null
, webBrowser,
new
object
[] { silent });
}
}
}
private
void
btnBack_Click(
object
sender, RoutedEventArgs e)
{
//webBrowser = new WebBrowser();
//Cef.Shutdown();
DeleteDirectory(tempDirPath);
if
(prevWindow !=
null
)
{
this
.Hide();
prevWindow.Show();
}
else
{
CefTest currentWindow =
this
;
MainWindow obj =
new
MainWindow(prevSelection);
obj.Show();
currentWindow.Visibility = Visibility.Hidden;
}
}
private
void
btnHome_Click(
object
sender, RoutedEventArgs e)
{
//webBrowser = new WebBrowser();
DeleteDirectory(tempDirPath);
List_standards frmList_standards =
new
VISL.List_standards(
this
);
frmList_standards.Show();
}
private
void
btnInfo_Click(
object
sender, RoutedEventArgs e)
{
//webBrowser = new WebBrowser();
DeleteDirectory(tempDirPath);
AbountUs frmAboutUs =
new
AbountUs(
this
);
frmAboutUs.Show();
}
private
void
Window_Closed(
object
sender, EventArgs e)
{
//webBrowser = new WebBrowser();
// Cef.Shutdown();
//webBrowser.Source = null;
//DeleteDirectory(tempDirPath);
/// Cef.Shutdown();
DeleteDirectory(tempDirPath);
}
}
}
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
How to switch usercontrols statically
GUI on top of a big PowerShell PowerCLI script