I'm using a simple open file dialogue to open a video file and play it via VLC. All works great, but I can NOT get the volume to mute for the life of me.
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.ShowDialog();
if (ofd.FileName != "")
{
vlc.addTarget("file:///" + ofd.FileName, null,AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0);
vlc.play();
vlc.AutoLoop = true;
vlc.Volume = 0;
vlc.toggleMute();
}
I have tried setting volume to 0 and there toggleMute function with no luck. I have also tried doing the mute functionality in the playEvent, with no luck. Could anyone shine some light on the situation?
EDIT: So, I tossed in a System.Threading.Thread.Sleep(1000); before my call to adjust the volume and mute. To my surprise, the volume is muted after a one second delay. Does anyone have a "real" fix for this as it seems like it could cause issues / not work correctly on slower machines
This issue occurse since VLC 2.0.9.
VLC version 2.0.8 doenst need an delay.
All versions >2.0.8 need delays...
Solution is use version 2.0.8 and it works fine.
/// <summary>
/// Play a filename
/// </summary>
/// <param name="fileName">filename</param>
public void Play(string fileName)
{
this.VlcControl.Media = new Vlc.DotNet.Core.Medias.PathMedia(fileName);
Task.Factory.StartNew(this.Mute);
}
/// <summary>
/// Mute audio
/// </summary>
private void Mute()
{
this.VlcControl.AudioProperties.IsMute = true;
if (!this.VlcControl.AudioProperties.IsMute)
{
// Retry mute
Task.Factory.StartNew(this.Mute);
}
}
Related
With the new MRTK2 I'm looking to disable spatial mapping after we are done using it to place GameObjects. I'm stuck on what exactly to call in the namespace or on the service to do this at run time.
I've tried: MixedRealityToolkit.SpatialAwarenessSystem.SuspendObservers();
This has no effect. I could disable the entire "Spatial Awareness System" GameObject, but this would be a hack.
What I need is the proper call that would disable the system entirely so that resources are freed up when it is no longer useful?
Additionally, a little insight into how we are to access the service system correctly would be of great help.
You can use the following code to disable/enable the spatial awareness system:
if (disable)
{
// disable
MixedRealityToolkit.SpatialAwarenessSystem.Disable();
}
else
{
// enable
MixedRealityToolkit.SpatialAwarenessSystem.Enable()
}
You can use the following code to enable/disable just the visualization but keep the colliders on:
foreach(var observer in MixedRealityToolkit.SpatialAwarenessSystem.GetObservers())
{
var meshObserver = observer as IMixedRealitySpatialAwarenessMeshObserver;
if (meshObserver != null)
{
meshObserver.DisplayOption = SpatialAwarenessMeshDisplayOptions.None;
}
}
You can read more documentation about the Spatial Awareness system in MRTK on the mrtk github.io site at Spatial Awareness System Usage guide
I would have expected the SuspendObservers() method to result in no new meshes being displayed. Do you see the meshes changing after suspending?
It is by design for the meshes to remain visible until the application explicitly sets their visibility to None via the IMixedRealitySpatialAwarenessMeshObserver.DisplayOption property.
Thanks!
Note the previous answer doesn't work due to recent changes to the MRTK framework.
Link for SpatialAwareness DataProvidershere
Code pasted from said link:
IMixedRealityDataProviderAccess dataProviderAccess =
CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
if (dataProviderAccess != null)
{
IReadOnlyList<IMixedRealitySpatialAwarenessMeshObserver> observers =
dataProviderAccess.GetDataProviders<IMixedRealitySpatialAwarenessMeshObserver>();
foreach (IMixedRealitySpatialAwarenessMeshObserver observer in observers)
{
// Set the mesh to use the occlusion material
observer.DisplayOption = SpatialMeshDisplayOptions.Occlusion;
}
}
[AddComponentMenu("Scripts/MRTK/Examples/ClearSpatialObservations")]
public class ClearSpatialObservations : MonoBehaviour
{
/// <summary>
/// Indicates whether observations are to be cleared (true) or if the observer is to be resumed (false).
/// </summary>
private bool clearObservations = true;
/// <summary>
/// Toggles the state of the observers.
/// </summary>
public void ToggleObservers()
{
var spatialAwarenessSystem = CoreServices.SpatialAwarenessSystem;
if (spatialAwarenessSystem != null)
{
if (clearObservations)
{
spatialAwarenessSystem.SuspendObservers();
spatialAwarenessSystem.ClearObservations();
clearObservations = false;
}
else
{
spatialAwarenessSystem.ResumeObservers();
clearObservations = true;
}
}
}
}
I am trying to edit a couple of settings in SolidWork's options menu through a C# program I wrote. The code is below:
using System;
using System.IO;
using SldWorks;
using SwConst;
static void Main(string[] args)
{
SldWorks.SldWorks swApp;
swApp = new SldWorks.SldWorks();
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSingleCommandPerPick, true); /// Single command per pick
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEditMacroAfterRecord, true); /// Automatically edit macro after recording
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUserEnableFreezeBar, true); /// Enable Freeze bar
Console.WriteLine("Settings applied");
}
The intended purpose of this program is to toggle those three options (checkboxes) to true. So far this does not work at all. The options still stay the same even after I run the program. Am I missing anything or is my code wrong?
Try this (for example, mouse speed):
//View rotation - Mouse speed
bool boolstatus = swApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swViewRotationMouseSpeed, 56);
Thanks to Solidworks API:
http://help.solidworks.com/2012/English/api/sldworksapi/Get_and_Set_User_Preferences_Example_CSharp.htm
Try using the following to get the COM object while SolidWorks is running.
Try
{
SldWorks swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSingleCommandPerPick, true); /// Single command per pick
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEditMacroAfterRecord, true); /// Automatically edit macro after recording
swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swUserEnableFreezeBar, true); /// Enable Freeze bar
Console.WriteLine("Settings applied");
}
catch()
{
Console.WriteLine("Failed to get SolidWorks");
}
I want to make a simple app that will allow me to check few parameters of every frame of preview, but I got stuck at running and stopping preview.
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
MediaCapture _MediaCapture;
bool _recording;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var rearCamera = devices[0];
if (devices.Count > 0)
{
rearCamera = devices.Single(currDev =>
currDev.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
);
}
_MediaCapture = new MediaCapture();
await _MediaCapture.InitializeAsync(new MediaCaptureInitializationSettings() { VideoDeviceId = rearCamera.Id });
// this is CaptureElement
xCapture.Source = _MediaCapture;
_recording = false;
}
protected override async void OnNavigatedFrom(NavigationEventArgs e)
{
if(_MediaCapture != null)
{
await _MediaCapture.StopPreviewAsync();
await _MediaCapture.StopRecordAsync();
_MediaCapture.Dispose();
_MediaCapture = null;
xCapture.Source = null;
}
base.OnNavigatedFrom(e);
}
// button click handler
private async void StartMeasure(object sender, RoutedEventArgs e)
{
if (_recording)
{
//await _MediaCapture.StopPreviewAsync();
_MediaCapture.VideoDeviceController.TorchControl.Enabled = false;
_recording = false;
}
else
{
//await _MediaCapture.StartPreviewAsync();
_MediaCapture.VideoDeviceController.TorchControl.Enabled = true;
_recording = true;
}
}
}
In this form it works perfectly.
If I uncomment those preview lines it works, but only once.
If I press the button three times: on, off and on again I get exception at line with enabling TorchControl.
System.Exception: Exception from HRESULT: 0xE801000D at Windows.Media.Devices.TorchControl.put_Enabled(Boolean value) at Pulsometr3.MainPage.d__d.MoveNext()
The HRESULT varies.
Whats even more weird, it sometimes freezes the phone (like 2 out of 3 times) and I need to hold Power + Volume Down.
I tried decorating all methods with [STAThread], but it didn't help (http://technet.microsoft.com/en-ca/br226599).
What's even more more interesting, when I hold operations by debbuger using F10 to step over lines I am able to toggle preview as many times as I possibly want. It's werid, since debugger hold all threads, right? So in theory there is no difference?
Also, phone sometimes freezes on deploy... And that's just annoying.
Any ideas?
I've got exactly into this...for some reason microsoft does not care much for it's successor OS to WP8, which makes me really sad. But it was also a half year ago during summer, I've tried this, maybe you can give a shot to googling on application consents and also double check your app manifests, if you have front/rear camera and webcam ticked in :) Besides that if it won't work, then bad luck, you are ought to stick with wp 8.0 version, which works exactly the same on wp 8.1 so do not worry :) also other libs like facebook stuff or parse.com won't work on wp 8.1 C# :)
I think your problem is the page cache enabled. Try to remove this line in your code this.NavigationCacheMode = NavigationCacheMode.Required;
if I understand correctly the button has a handler StartMeasure which is an async method and awaits for Start/StopPreviewAsync().
The problem might be that if you click the button more than once the one action might be still awaited(in progress) and the other one is also called, this might cause some issues because it will try to start and stop the preview at the same time which will probably lead to some race conditions.
You could check this by adding a lock to manage the access to the capture manager in order to test this. Also checking the bool and assigning it after an awaited operation is for sure not an atomic operation so that could lead to race conditions too.
private object locker;
private async void StartMeasure(object sender, RoutedEventArgs e)
{
lock (locker)
{
if (_recording)
{
await _MediaCapture.StopPreviewAsync();
}
else
{
await _MediaCapture.StartPreviewAsync();
}
_recording = !_recording;
_MediaCapture.VideoDeviceController.TorchControl.Enabled = _recording;
}
}
In my application I'm getting the video file as a byte[] from the database and my requirement is like to play that video file using WPF media Element.
Just want to know what is the best and elegant way to do that.
you can use this function for playing videos in wpf using media element ...
It was given best results and i had already use this one...
pls go through this link for More Information On how to play video in wpf uisng media element
/// <summary>
/// Handles Drop Event for Media Items.
/// </summary>
private void Media_Drop(object sender, DragEventArgs e)
{
string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true)
as string[];
//keep a dictionary of added files
foreach (string f in fileNames)
{
if (IsValidMediaItem(f))
mediaItems.Add(f.Substring(f.LastIndexOf(#"\")+1),
new MediaItem(#f,0));
}
//now add to the list
foreach (MediaItem mi in mediaItems.Values)
lstMediaItems.Items.Add(mi);
// Mark the event as handled,
// so the control's native Drop handler is not called.
e.Handled = true;
}
/// <summary>
/// check to see if dragged items are valid
/// </summary>
/// <returns>true if filename is valid</returns>
private bool IsValidMediaItem(string filename)
{
bool isValid = false;
string fileExtesion = filename.Substring(filename.LastIndexOf("."));
foreach (string s in MediaItem.allowableMediaTypes)
{
if (s.Equals(fileExtesion,
StringComparison.CurrentCultureIgnoreCase))
isValid = true;
}
return isValid;
}
I hope it will helps you...
I'm a newbie to WMI and I need to implement RegistryValueChangeEvent in a C# service.
I need an event handler that gets triggered each time any one of a set of registry values is changed. I want behavior similar to the FileSystemWatcher class's Changed event, but for registry values.
If there's some other technique I could use to accomplish the same task, I'd appreciate that as well. My minimum requirement is that it be a better solution than what I have now: polling every 20 seconds and comparing the registry value with the last result.
Please provide example code in your answer. If I can get an example for watching just one registry value, that would be fine.
I need a solution in .Net 2.0
Thanks.
WMI can sometimes be interesting to work with...I think I understand your question, so take a look at the code snippet below and let me know if it's what you're looking for.
// ---------------------------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="">
//
// </copyright>
// <summary>
// Defines the WmiChangeEventTester type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace WmiExample
{
using System;
using System.Management;
/// <summary>
/// </summary>
public class WmiChangeEventTester
{
/// <summary>
/// Initializes a new instance of the <see cref="WmiChangeEventTester"/> class.
/// </summary>
public WmiChangeEventTester()
{
try
{
// Your query goes below; "KeyPath" is the key in the registry that you
// want to monitor for changes. Make sure you escape the \ character.
WqlEventQuery query = new WqlEventQuery(
"SELECT * FROM RegistryValueChangeEvent WHERE " +
"Hive = 'HKEY_LOCAL_MACHINE'" +
#"AND KeyPath = 'SOFTWARE\\Microsoft\\.NETFramework' AND ValueName='InstallRoot'");
ManagementEventWatcher watcher = new ManagementEventWatcher(query);
Console.WriteLine("Waiting for an event...");
// Set up the delegate that will handle the change event.
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
// Start listening for events.
watcher.Start();
// Do something while waiting for events. In your application,
// this would just be continuing business as usual.
System.Threading.Thread.Sleep(100000000);
// Stop listening for events.
watcher.Stop();
}
catch (ManagementException managementException)
{
Console.WriteLine("An error occurred: " + managementException.Message);
}
}
/// <summary>
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void HandleEvent(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Received an event.");
// RegistryKeyChangeEvent occurs here; do something.
}
/// <summary>
/// </summary>
public static void Main()
{
// Just calls the class above to check for events...
WmiChangeEventTester receiveEvent = new WmiChangeEventTester();
}
}
}
You really don't need WMI, as others have pointed out. I too have used RegistryMonitor with no problems.
If you need an example, there's already example code for the RegistryMonitor on the page itself. Did you scroll down to this bit on the code project:
public class MonitorSample
{
static void Main()
{
RegistryMonitor monitor = new
RegistryMonitor(RegistryHive.CurrentUser, "Environment");
monitor.RegChanged += new EventHandler(OnRegChanged);
monitor.Start();
while(true);
monitor.Stop();
}
private void OnRegChanged(object sender, EventArgs e)
{
Console.WriteLine("registry key has changed");
}
}
Are you limited to WMI?
If not you can use RegNotifyChangeKeyValue wrappers like RegistryMonitor
You'll need to utilize WMI for it. See http://msdn.microsoft.com/en-us/library/aa393035.aspx