SoundPlayer not working when visual studio application is published - c#

When I run in Microsoft Visual Studio, the sound works. However, after I published it, the sound doenst work. The sound properties are set to Content. Can someone help? Thanks
private void InitializeSound()
{
// Create an instance of the SoundPlayer class.
player = new SoundPlayer(#"Sounds\sirenpolice3.wav");
}
enter image description here

try this sample
using (var player = new SoundPlayer(#"Sounds\sirenpolice3.wav"))
{
// Use PlaySync to load and then play the sound.
// ... The program will pause until the sound is complete.
player.PlaySync();
}

Related

C# WPF application crashing when playing 16 players

I am running into an issue with my C# WPF application crashing silently when I am trying to play on 16 VideoViews. I did not see any error messaged popup, nor did I see anything in Windows Event viewer.
Each player instance have WindowsFormHost and hosting a VideoView in that and I am playing RTSP streams on them.
Crash time is not fixed, sometimes it crash after 2 hours, and sometimes after 7-8 hours.
Core.Initialize(AppInfo.VlcDir.FullName);
private LibVLC libVlc = null;
private LibVLCSharp.Shared.MediaPlayer mediaPlayer = null;
this.libVlc = new LibVLC(this.GetParsedPlayerOptions().ToArray());
this.mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(this.libVlc);
this.videoPlayer.MediaPlayer = this.mediaPlayer;
this.mediaPlayer.Volume = 0;
this.mediaPlayer.EnableKeyInput = false;
this.mediaPlayer.EnableMouseInput = false;
// Then I added a bunch of event handlers for VideoView and MediaPlayer.
// Then I have a different function which plays videos
if (this.mediaPlayer != null)
{
var media = new Media(this.libVlc,GetPlaybackStreamUrl(this.Server), FromType.FromLocation);
this.mediaPlayer.Media = media;
this.mediaPlayer.Play();
try
{
media.Dispose();
}
catch
{
}
}
Please let me know if you need any more information.
Any suggestions of what I could be doing wrong, or anything missing?
I am running on Windows 10. Visual Studio 2019, application compiled as X86.
I am not able to find the option to upload log file, but I did attach that to the issue on videolan forum, which can be found here: https://code.videolan.org/videolan/LibVLCSharp/-/issues/564
Thanks.
I was not able to find the problem with the code or the crash stack for where it's dying.
But I was able to fix the problem by increasing the address space, by using editbin to add /LARGEADDRESSSPACE to process post build.

C#, No video, audio only, VLC using multiple forms, Black Screen?

Can someone please tell me whey I am getting a black screen with no video, only sound?
private void screen1btnPlay_Click(object sender, EventArgs e)
{
ScreenOne playScreen1 = new ScreenOne();
playScreen1.PlayScreenOne();
}
... and the other form is like this:
public partial class ScreenOne : Form
{
public ScreenOne()
{
InitializeComponent();
}
public void PlayScreenOne()
{
axVLCPlugin21.playlist.add("file:///" + #"Filepath", null);
axVLCPlugin21.playlist.play();
}
}
Sound works fine, but no video. All the properties of the VLC are left to default, is there something I need to change when using this plugin across multiple forms? Anyone know what's wrong?
Update:: I rebuilt the program in WPF and I am having the same problem. When I have a button on the second form (same form as player) it works fine, as soon as I call it from the main form, sound only. ugh!
I dont know but i can give some solution suggestions,
Make sure the VLC program is installed as 32-bit. I dont know, I've solved a problem that way.
I think high probabilty your problem is based on about "C:\Program Files (x86)\VideoLAN\VLC\plugins" Check your plugins. maybe your audio_filter, audio_mixer, audio_output plugins are missing.
you can remove Vlc, then download and install last VLC 32 bit.
I think that will solve your problem. Dont forget AxAXVLC works with vlc plugins.
I figured out my problem on my own!
When I was creating this instance,
ScreenOne playScreen1 = new ScreenOne();
I was actually creating a redundant instance of what I was trying to do, I'm not sure if that's the right way to put it but I basically already had an instance of the second form and was making another separate instance of the form that was named differently.
I already had in my code to open the second form
Screen2 Screen2 = new Screen2();
private void openScreen2Button_Click(object sender, EventArgs e)
{
Screen2.Show();
}
Then later was doing this which is WRONG, I was adding playscreen1 when I should still have been using Screen2.
Screen2 playScreen1 = new Screen2();
playScreen1.PlayScreenOne();
So when I wanted to use the method to play the media player on the second form from the first one, I just needed to use the same instance of Screen2 that I had created to open the form to begin with instead of created a new instance for what method I wanted to use.
IDK if my explanation makes sense, or maybe its basics to most people (I'm a noob), but if anyone comes across this problem, message me and I'll try to help.
o7

saving files on IOS from a Unity 3D game

Ok, so I followed the tutorial at unity3d.com (located here)
Just so that you dont have to or want to watch the whole video , here is the save/load functions.
//This one saves/creates the file
void OnDisable()
{
BinaryFormatter binFormatter = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/savedgame.dat");
GameData data = new GameData();
data.coinAmount = coinAmount;
data.upgradeLevel = upgradeLevel;
binFormatter.Serialize(file, data);
file.Close();
}
//And this one loads it
void OnEnable()
{
if (File.Exists(Application.persistentDataPath + "/savedgame.dat"))
{
BinaryFormatter binFormatter = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedgame.dat",FileMode.Open);
GameData data = (GameData)binFormatter.Deserialize(file) ;
file.Close();
coinAmount = data.coinAmount;
upgradeLevel = data.upgradeLevel;
}
}
I'm using OnDisable/OnEnable so that my game autosaves every time the users exits. This works on a pc and a mac, but when I build it to the Ipad air2 and its like nothing happens. Xcode trows a exception that says unknown filename(-1).
Thanks in advance for the help
Upon further investigation on android it turns out that the file gets created and the game reads data from it. The problems is here :
data.coinAmount = coinAmount;
data.upgradeLevel = upgradeLevel;
For some reason this does not write the correct data when the app runs on Android(probably the same for IOS).
When I supply a hard coded value i.e : data.coinAmount = 100; the game then reads it correctly.
Upon even further investigation turns out that the code work when you call Application.quit but does not work when we "force close" the app i.e using the ipads front button. Need help with this
Ok, so turns out when we stop a Unity game with the home button on a mobile device the methods OnEnable/OnDisable dont seem to we called or working properly. So my solution to the problem is to migrate the save code to the OnApplicationPause(bool pauseStatus) method. After a few tests this seems to be called every time you press the home screen, thus making sure that the game autosaves.
However this only fixed the issue on android devices. Someone please tells me what happens when a IOS user presses the home button so I can freakin save my game when that happens.
Fixed the issue. After some debugging it turns out that ios and .Net JIT do not like each other. This code fixes the issue:
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
}
I recommend putting it in the Awake() method.

Can’t play SoundEffects with Monogame 3.2 for Windows 7 Desktop (DirectX)

For some reason I cannot get Monogame to play any sounds through SoundEffect or SoundEffectInstance.
With a workaround I can get Songs to play, but still not SoundEffects or SoundEffectInstances.
If I run my example below through “native XNA” everything works fine.
I’m using:
Monogame 3.2 for Windows Desktop (DirectX)
Windows 7
Visual Studio Express 2013
Example:
SoundEffect effect;
SoundEffectInstance instance;
Song song;
protected override void LoadContent()
{
// Load sound, no errors and the objects get filled with data.
effect = Content.Load<SoundEffect>("myWavFileAsSoundEffect"); // Loaded with ContentProcessor = "Sound Effect - XNA Framework"
song = Content.Load<Song>("myWavFileAsSong"); // Loaded with ContentProcessor = "Song - XNA Framework"
instance = effect.CreateInstance();
// Set volume to 100%, just in case
SoundEffect.MasterVolume = 1.0f;
MediaPlayer.Volume = 1.0f;
instance.Volume = 1.0f;
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
// Play instance. Nothing happens.
instance.Play();
// Play effect. Nothing happens.
bool success = effect.Play(1.0f, 0.0f, 0.0f);
// success is true
// Play song.
try
{
// Error
// HRESULT: [0x80004002], Module: [General], ApiCode: [E_NOINTERFACE/No such interface supported]
MediaPlayer.Play(song);
}
catch (Exception)
{
// Play the song again
// Plays fine
MediaPlayer.Play(song);
}
}
base.Update(gameTime);
}
Does anyone know what might be wrong? Why can’t I play any SoundEffects or SoundEffectInstances?
I had the exact same problem but on Windows 10. The solution for me was to reinstall Directx.
Webinstaller: https://www.microsoft.com/en-us/download/details.aspx?id=35&84e4d527-1a2f-c70a-8906-a877ec4baada=1
Hope this helps
Even I was having problem with when added .wav files.But when I added .xnb files which is generated after building the XNA project(files are in bin\content folder),errors gone.Could you please try with xnb files.

Webcams, C#, and a reliable wrapper

I'm in dire need of a replacement for a wrapper being used in a C# application. Basically, what we need to do is attach a webcam feed to one of two picture boxes. This will be used to take still images at the push of a button, which may detach the camera feed and attach the still image to that picture box, then reattach the camera feed later. We had previously found some free code to utilize with a CaptureDevice.cs file and Pinvoke.dll to tie it into avicap32.dll. Unfortunately, this seems to have random, intermittent errors that cannot be reliably reproduced. It's just too flaky. At some random point, one of those picture boxes may go black and won't show the feed until the picture is taken, at which point the proper picture is attached to the picture box. Then, even if there's only one webcam attached, it'll keep prompting for the webcam to be selected, something it wouldn't do otherwise.
Quite frankly, I'm surprised and dismayed that Microsoft hasn't included anything in .NET to cover webcam video feeds. I'm looking for something reliable and relatively simple to implement to replace this buggy webcam system.
It is time to use MediaCapture object. Use this sample for MS Windows 10 https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraStarterKit/
And read this article as well http://www.codepool.biz/csharp-camera-api-video-frame.html
May I suggest
http://www.emgu.com/wiki/index.php/Main_Page
I have used OpenCV in many C++ libraries and it seems to work very well for webcams from other things I've tried. Emgu is just a C# wrapper for OpenCV.
Here is a sample project to try it out on. It's very basic and simple, but should work right away.
http://dl.dropbox.com/u/18919663/vs%20samples/OpenCVCSharpTest.zip (just uploaded)
Sample:
using Emgu.CV;
using Emgu.CV.Structure;
...
public partial class Form1 : Form
{
public Capture cvWebCam;
public Form1()
{
InitializeComponent();
try
{
cvWebCam = new Capture();
timer1.Start();
}
catch
{
Console.WriteLine("Default camera not found or could not start");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (cvWebCam != null)
using (Emgu.CV.Image<Bgr, byte> frame = cvWebCam.QueryFrame())
{
pictureBox1.BackgroundImage = frame.ToBitmap();
}
}
}
Try DirectShow.net- it's a free wrapper library to access DirectShow functionality from .NET:
http://directshownet.sourceforge.net
Its code samples contain a sample app for capturing video from webcams, too:
http://sourceforge.net/projects/directshownet/files/DirectShowSamples/

Categories