TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shruthi Kadam
NA
69
2.3k
to enable audio controls in cefsharp Browser
Feb 15 2021 7:01 AM
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);
}
}
}
Reply
Answers (
0
)
How to switch usercontrols statically
GUI on top of a big PowerShell PowerCLI script