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
- {
-
-
-
- public partial class CefTest : Window
- {
- Window prevWindow;
- ContentMasterDTO content;
- string tempDirPath = string.Empty;
-
- 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();
- }
-
-
-
-
-
-
-
-
-
- }
- public void InitHTMLPlayer()
- {
- try
- {
- #region Display HTML
- BoxedAppSDK.NativeMethods.BoxedAppSDK_SetContext("29c3c554-6033-4eb5-95fe-cadc013c229e");
- BoxedAppSDK.NativeMethods.BoxedAppSDK_Init();
-
-
- 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",
- 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
- )
- )
- {
-
-
- }
-
- tempDirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\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";
- }
-
- web.Address = tempDirPath;
-
-
-
-
-
-
-
-
-
-
-
-
-
- #endregion
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void ReadWriteStream()
- {
- Stream readStream = File.Open(@"virtualZipFile.zip", FileMode.Open);
- Stream writeStream = File.Open(tempDirPath + "\\tempVirtualFile.zip", FileMode.Create);
- int Length = 1024 * 1024;
- Byte[] buffer = new Byte[1024 * 1024];
- int bytesRead = 1;
-
- 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);
-
- foreach (string file in fileList)
- {
- FileAttributes attr = File.GetAttributes(file);
-
-
- File.Delete(file);
- }
-
- foreach (string directory in Directory.GetDirectories(path))
- {
- DeleteDirectory(directory);
- }
-
- Directory.Delete(path, true);
- }
- }
- catch (Exception ex)
- {
- Console.Write(ex.Message);
- }
- }
- private void webBrowser_Navigated(object sender, NavigationEventArgs e)
- {
-
- }
- 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");
-
- 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)
- {
-
-
- 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)
- {
-
- DeleteDirectory(tempDirPath);
- List_standards frmList_standards = new VISL.List_standards(this);
- frmList_standards.Show();
- }
- private void btnInfo_Click(object sender, RoutedEventArgs e)
- {
-
- DeleteDirectory(tempDirPath);
- AbountUs frmAboutUs = new AbountUs(this);
- frmAboutUs.Show();
- }
- private void Window_Closed(object sender, EventArgs e)
- {
-
-
-
-
-
- DeleteDirectory(tempDirPath);
- }
- }
- }