c# winform windows media player playing only audio no video - c#

I am working on a project and want to play a video from my computer with window media player on a window form , but its only playing audio and no video , i have added the wmp.dll
private void button1_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = #"C:\Users\Admin\Desktop\d1.mp4";
}
enter image description here

Related

Why is my webcam only taking one frame upon execution via Emgu?

I have some code that takes opens my webcam via Emgu upon loading Form1. The problem I have, though, is that I can only load the first frame.
I have tried to use Webcam() to create a video capture, but it only takes the first frame. If I assign this code to a button, it will take only 1 frame upon each button press. I have tried to create a continuation of the video capture using Webcam2(), but the the picturebox had 1 FPS and would exponentially use more memory overtime.
I know it is not my computer as I was able to use webcam via emgu using its facial recognition viewer (I used the guide at https://www.youtube.com/watch?v=ZSxHyp4OZx0 to test this out). Unfortunately, while I am creating a a similar project, I am using AWS for the facial recognition. Still, I was able to run the Emgu camera viewer without any issues or bad framerates. My Laptop is a 2022 high end gaming laptop.
Here is the code
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
showit();
//Application.Idle += Webcam2;
//Webcam();
}
private void Webcam2(object sender, EventArgs e)
{
VideoCapture capture = new VideoCapture();
pictureBox1.Image = capture.QueryFrame().ToBitmap();
}
private void Webcam()
{
VideoCapture capture = new VideoCapture();
pictureBox1.Image = capture.QueryFrame().ToBitmap();
}
}
Any idea what is going on?

C# axWindowsMediaPlayer Change Video Position with Custom Trackbar

I have a axWindowsMediaPlayer on WinForm with uiMode=none. I am using my custom controls to handle playback. I am using this method to associate a trackBar with axWindowsMediaPlayer.
I want to change the video position (jump to specific time) when the user scrolls the trackBar, just like windows media player.
private void trackBar_Scroll(object sender, EventArgs e)
{
if (axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer.Ctlcontrols.currentPosition = trackBar.Value;
}
}
This is not working. I have checked many Stackoverflow answers including this, this, and the Microsoft documentation but none is working.
I have two objectives:
When playing media, the trackBar should show the current position of the media file being played. This is working fine.
When the user scrolls the trackBar, the media player should change the video current position based on the trackBar value. This is not working.
Any help will be highly appreciated.
I solved the issue. The problem was not with the media player, the problem was with the media files being played with the axWindowsMediaPlayer.
axWindowsMediaPlayer plays the files such as MKV fine, but if the proper codecs are not installed, the Ctlcontrols mainly the Trackbar does not work from code or UI. With natively supported formats, this code works perfectly fine.
private void trackBar_Scroll(object sender, EventArgs e)
{
if (axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
axWindowsMediaPlayer.Ctlcontrols.currentPosition = trackBar.Value;
}
For media files not natively supported, their codecs need to be installed. For details of supported file formats, see this KB article File types supported by Windows Media Player

Windows Media Player - Hide player after it is done playing

I am creating a game, I want to display a short tutorial video to the player after they have registered. I am using a windows media player control. I don't know how to hide the video after it has finished playing ?
I tried using the following:
WMP.Ctlcontrols.play();
Thread.Sleep(3000);
WMP.Dispose();
I am using the disposing as a way to close down the video. I tried hide and close as well but they close the video before it's finished playing, after 3 seconds.
You can handle PlayStateChange event of control and check if e.newState==1, it means the playing has been stopped. Then you can hide the control.
void axWindowsMediaPlayer1_PlayStateChange(object sender,
AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if(e.newState== 1) // Stopped
axWindowsMediaPlayer1.Hide();
}

C# youtube video not playing anymore

Hello I have an application that used to allow me to watch videos from youtube, but now the screen is completely black, I cannot view videos. I am using axmediaplayer and here is my code.
private void Form1_Load(object sender, EventArgs e)
{
// play video in embedded media player
axWindowsMediaPlayer1.URL = "http://www.youtube.com/v/Of9JCZ6zraQ";
}
Is it a change made on youtube or does any one know alternatives? it used to work before but not it is not working any more. does any one know what the problem is please?

How to play IMFMediaEngine background audio while SpeechSynthesizer is playing

I want to play Windows Phone 8's Speech Synthesizer while background audio is playing. But every time, I activate the Speech Synthesizer, the background audio stops playing, and resumes after the synthesizer finishes.
Any suggestions?
Thanks.
Some code snippets below:
Background Audio: using IMFMediaEngine in C++, plays successfully.
Microsoft::WRL::ComPtr<IMFMediaEngine> m_mediaEngine;
m_mediaEngine->Play();
In C# / XAML, I have a XAML page with a button, when I click on it, it plays from WP8's latest Speech classes. Plays the text.
using Windows.Phone.Speech.Synthesis;
public async void SpeakText(string text)
{
SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
await speechSynthesizer.SpeakTextAsync(text);
}
I tried putting the SpeakTextAsync through threads, but I guess I'm doing it all wrong, because I still can't get both audio playing at the same time.
private void bubble_Click(object sender, RoutedEventArgs e)
{
App.Manager.SpeakText("hello how are you");
// TRY 1: plays text only, background doesn't play
//new Thread(() =>
//{
// App.Manager.SpeakText(chinese);
//}).Start();
// TRY 2: plays text only, background doesn't play
//Deployment.Current.Dispatcher.BeginInvoke(() =>
//{
// App.Manager.SpeakText(chinese);
//});
// TRY 3: plays text only, background doesn't play
//ThreadPool.QueueUserWorkItem(new WaitCallback(SpeakTextProc));
}
private void SpeakTextProc(Object stateInfo)
{
App.Manager.SpeakText("Hello how are you");
}
On Windows Phone 7, I was able to get two separate audio streams using XNA but seeing how that XNA isn't supported for further development on Windows Phone 8, that's not a great solution for you good luck.

Categories

Resources