C# Windows Media Player video playing behind form - c#

I am trying to play a video after a certain event is triggered.
Currently the video starts playing but it stays behind the form (You can see it playing in the opacity of the toolbar). I have tried to bring it to the front, refresh it, select it, update it but none of it seems to work. Also, if I manually open the windows media player program and close it the video "jumps" to the front of the screen.
This is the code used to start playing the video
wmp.settings.autoStart = true;
wmp.uiMode = "none";
wmp.Visible = true;
wmp.URL = #"C:\folder\video.mp4";
wmp.Update();
I also check if the video is still playing using the Status_Change event to set it to full screen and try to bring it to front
private void wmp_StatusChange(object sender, EventArgs e)
{
if (wmp.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
wmp.fullScreen = true;
wmp.BringToFront();
wmp.Update();
}
}
Despite these efforts the video still plays behind the form. Any suggestions would be appreciated!

Related

Failed to take photo with the webcam using the library AForge

I am making use of the AForge class library.
From this library I am using VideoSourcePlayer to take photos with the webcam.
My purpose is to create a function that allows the user to photograph images to establish them as company logo.
Not only can you choose images from the computer, but you can also capture images from the outside through the camera, since you may only want to transfer a logo of a physical support (paper) to the program.
As commented earlier in SO, (how to pause a video file played using videosourceplayer), VideoSourcePlayer does not have a Pause method or any function that allows to freeze the image.
Yes, it is true that it has the GetCurrentFrame() method, but that only gets a Bitmap from the current frame that must be passed to a PictureBox.
But I want that when the user clicks the button Capture the image of the VideoSourcePlayer simulate being frozen, and when the user presses the Delete button because he did not like the photo, then the image stops being frozen and recovers its movement.
Logic is like pausing or playing a video.
Well, there's no method for it, so I decided to look for another way to get this, and ...
If a picture is taken, use a PictureBox that contains the last frame and that is displayed on the VideoSourcePlayer, but if it is deleted, then the PictureBox is removed and the VideoSourcePlayer is returned with video.
private readonly Bitmap EmptyBitmap;
private void CaptureBtn_Click(object sender, EventArgs e)
{
Bitmap bitmap = this.VideoSource.GetCurrentVideoFrame();
ShowTakedFrame(bitmap, false);
}
private void ShowTakedFrame(Bitmap Frame, bool remove)
{
var picture = new System.Windows.Forms.PictureBox();
picture.Size = this.VideoSource.Size;
picture.Location = this.VideoSource.Location;
if (!remove)
{
this.VideoSource.Stop();
picture.Image = Frame;
this.Controls.Remove(VideoSource);
this.Controls.Add(picture);
}
else
{
this.Controls.Remove(picture);
this.Controls.Add(VideoSource);
this.VideoSource.VideoSource = this.CaptureDevice;
this.VideoSource.Start();
}
}
private void DeleteBtn_Click(object sender, EventArgs e)
{
ShowTakedFrame(EmptyBitmap, true);
}
My problem is that when capturing the photo, the image is a few seconds after the moment when you press the Capture button and when you delete the captured image, using the Delete button, the video of the VideoSourcePlayer is frozen.
Can someone help me with this?
The problem is that when you remove the PictureBox and add the VideoSourcePlayer, it creates a new object, that is, one that does not have the configuration properties of the previous one. My recommendation is that you create the capture in a different form.

C# - Xamarin Forms audio player stops working after 5 or 6 uses

I am using this implementation of an Audio Player in Xamarin
https://www.codeproject.com/Articles/1088094/Playing-audio-mp-File-in-Xamarin-Forms
I have a button in my code that, when pressed, plays a certain, short (1-2 seconds) tone.
The player in the link works well, but for some reason if I repeatedly press my button like 5 or 6 times the audio player doesnt work anymore. Even if I leave the page and come back the audio player still doesn't work. What could be causing this? I'm fearing that it might be a device security thing on Android, because why else would it play the first few times?
Here is my code for clicking the button
void PlayChordClicked(object sender, EventArgs e)
{
DependencyService.Get<IAudio>().PlayAudioFile(myMp3);
}
Everything else is exactly as copied from the tutorial.
Thanks!
With help from Gusman in the comments, I figured out that I was most likely crashing the app by not disposing of the MediaPlayer after using it.
I added these few lines in the Android "PlayAudioFile" method and it did the trick
player.Completion += delegate
{
player.Release();
player.Dispose();
};

C# playing embedded Windows Media Player in fullscreen

I'm working on my eyetracking Windows Forms application. I need to play a video and keep track of eye movements simultaneously. Eyetracking part is done, now I need to open a video. I can open a DialogBox to choose which video to play, but I need to have a fullscreen, in order to make more accurate operations.
In my VideoStream class I have got :
public static string videoPath;
public VideoStream(string path)
{
InitializeComponent();
videoPath = path;
axWindowsMediaPlayer1.URL = videoPath;
axWindowsMediaPlayer1.Dock = DockStyle.Fill;
}
with the dockstyle fill, I can make my form maximized, but the video is just playing in a small screen like this
but what I want is actually this
I tried to use axWindowsMediaPlayer1.fullScreen = true; but just expands the borders of the form, not the video itself. How can I solve this?
Try adding these lines after initializeComponent():
FormBorderStyle = FormBorderStyle.None;
WindowsState = FormWindowState.Maximized;
TopMost = true;

Windows Media Player seamless looping of video

I am implementing a Windows Media Player into my WinForms application. axWindowsMediaPlayer is in the application and it is working fine, but my issue is that there is a black-screen flicker in between the playing of the video. But the odd thing is that it does not flash the black screen in between the first and second times playing the video. So, this leads me to believe it must be some sort of buffering or something in which during the first play it keeps up fine but thereafter is has problems keeping up with the loading and also playing of the video at the same time.
So, basically what I wondering is if the best fix would be to somehow completely cache the video, or somehow pause it as it loads it again, and maybe I have to go about this all based on a timer or something to that effect. In any case, please let me know what, if anything is known for a fix to this problem of the blackscreen flicker in between looping of a video in a Winforms embedded Windows Media Player.
You can try to manually reset video current position using follow code. It will start video from beginning without any flicker.
AxWindowsMediaPlayer.Ctlcontrols.currentPosition = 0
Or use this within a timer tick event and when video is near end then manually play it from beginning like this.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If AxWindowsMediaPlayer1.Ctlcontrols.currentPosition > AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration - 0.01 Then
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0
End If
End Sub
I hope this helps.
private void timer1_Tick(object sender, EventArgs e)
{
if(axWindowsMediaPlayer1.Ctlcontrols.currentPosition > axWindowsMediaPlayer1.Ctlcontrols.currentItem.duration - 0.01)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0;
}
}
this code change currentPosition to 0 second when video running 0.01 milliseconds so that transition effect of black screen can be avoided

Lowering Zune volume and playing audio file?

At the moment in my app I pause any music the phone is playing and use a MediaElement to play any sounds. After the sound plays the music continues. Everything works fine but now I would like to lower the music volume rather than stop it.
1) Can this be done on wp7?
2) If so how? as I tried changing the volume like so.
void PauseMusic()
{
FrameworkDispatcher.Update();
// Pause the Zune player if it is already playing music.
if (!MediaPlayer.GameHasControl)
{
//MediaPlayer.Pause();
MediaPlayer.Volume = 0.7f;
resumeMediaPlayerAfterDone = true;
}
}
Audio is played like so.
void PlayAudioCue(string path)
{
PauseMusic();
AudioPlayer.Stop();
AudioPlayer.Source = new Uri("/Audio/" + path, UriKind.Relative);
}
void AudioPlayer_MediaOpened(object sender, RoutedEventArgs e)
{
AudioPlayer.Position = new TimeSpan(0);
AudioPlayer.Volume = 1;
AudioPlayer.Play();
}
First off, I bet you want to publish your app to the marketplace. It will fail the certification process. Look at 6.5.1 paragraph – Initial Launch Functionality
When the user is already playing music on the phone when the application is launched, the application must not pause, resume, or
stop the active music in the phone MediaQueue by calling the
Microsoft.Xna.Framework.Media.MediaPlayer class.
If the application plays its own background music or adjusts
background music volume, it must ask the user for consent to stop
playing/adjust the background music (e.g. message dialog or settings
menu). This prompt must occur each time the application launches,
unless there is an opt-in setting provided to the user and the user
has used this setting to opt-in.
More details
I'm not 100% sure, but you cannot lower the volume of user's music.

Categories