Recently I have started messing around with the VLC ActiveX plugin trying to play youtube videos in a WindowsFormApplication and I have run into some issues that I couldn't find any mention of or solution to. For simplicity I made a new project to demonstrate my problems:
private void button1_Click(object sender, EventArgs e)
{
Player.playlist.play();
}
private void button2_Click(object sender, EventArgs e)
{
url = textBox1.Text;
Player.playlist.add(url);
listBox1.Items.Add(url);
}
2 buttons, play and add to playlist.
Problem 1:
Audio cuts out a few seconds before the end of the video.
Problem 2:
I have been unable to get the control to play the next video in the playlist. It just reaches the end of the first video. If I click the play button again, it plays the first video. One thing I thought might be causing it was the AutoPlay property but it's set to true.
Problem 3:
The Player.playlist.next function, like most thing doesn't have a description and does not let me go to the next video in the playlist.
Problem 4:
The AutoLoop property does not work, assuming that it's supposed to get the control to loop a video.
Problems number 2 and 3 make me think that the songs aren't being added to the playlist correctly, but again I was unable to find any way to confirm or solve that issue.
Using VisualStudio 2015, VLC plugin version, as stated in the control properties, 3.0.1 Vetinari.
(edit) after testing I know that the videos are added to the playlist, but still it won't autoplay the next in playlist at the end.
Related
I´m beginner in C# coding. Especially, when it comes to use Wmp in C#. I work in visual studio 2017, on a project called "station information system" for a small, private railway in our country. The whole functionality of program I´ve done correctly, it works, so now I need to come up with an idea, how to make it playing. My program exports exact names of mp3 files into a hidden listbox. To generate patches I use this code:
axWindowsMediaPlayer1.URL = Path.Combine(Environment.CurrentDirectory, #"ZVUK\", listBox2.SelectedItem.ToString());
It works, so I came to the other functionality I need from Wmp. When Wmp plays the full song, I need it to change the index in listbox and go to second song, then third and so on. I used this condition:
if (axWindowsMediaPlayer1.playState() = WMPLib.WMPPlayState.wmppsMediaEnded)
The part "playState()" is underlined and it shows me an error: "Non-invocable member "axWindowsMediaPlayer1.playState" cannot be used like a method." I tried deleting brackets but it just underlined the whole part "axWindowsMediaPlayer1.playState". Can someone help me?
Thank you very much.
You can use the following code to play the file one by one.
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer player = new SoundPlayer(#"2.wav");
player.PlaySync();
player = new SoundPlayer(#"\1.wav");
player.PlaySync();
}
I am creating a WPF application using Kinect SDK 1.8
I want to press a button with hand.
private void playTeeth1Sound(object sender,RoutedEventArgs e)
{
System.Media.SoundPlayer teeth1_Sound = new System.Media.SoundPlayer(#"../../soundForKinect/1.wav");
teeth1_Sound.Play();
}
I don't see any Kinect specific code in your question, and I'm not sure what the questions is, but one thing to consider in the code snippet in your question is:
Every time this method is called (presumably when the button is pressed), it has to:
instantiate a new System.Media.SoundPlayer
load the sound file into teeth1_Sound
play the sound file with the Play() method
You might find there is a delay each time as the code re-instantiates teeth1_Sound and reloads the sound file? It might be easier to load all the sound files when the app is starting up, have them ready to Play() as soon as you need them?
I am very new at c# and visual studio and now i am learning all the tools.
At first i tried adding background sound to my form. I added a wav file trhough resources and i changed it's build action to embedded resources so that i can "play" the .exe file without problems at any other pc.Then i wrote this and it worked.
namespace audio
{
public partial class Form1 : Form
{
SoundPlayer sp = new SoundPlayer(Properties.Resources.back_sound);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
sp.Play();
}
}
}
Now i want to play a video file with windows media player.I added it through COM components and i added it to my form.I can make it play any video just by adding the video file at the debug folder and write this.
private void button1_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = "video.AVI";
}
But as before i want to add it to my resources so that i can execute the .exe file to aby other pc and by this way, i cant
I tried with ( following the same pattern with the sound file)
AxWindowsMediaPlayer player = new AxWindowsMediaPlayer(Properties.Resources.video);
( and inside the button player.play();)
and
WindowsMediaPlayer player = new WindowsMediaPlayer(Properties.Resources.video);
( and inside the button player.play();)
but no luck.
Can anyone help me, please?
Thanks in advance
UPDATE:
I tried a lot of things and nothing worked, so i thought that it would better to stream the videos directly from youtube. I went to COM components and i added to my form a SHOCKWAVE FLASH OBJECT. I took the url i wanted, i transformed it ( from www.youtube.com/watch?v=xxxxxxxxxxxx to www.youtube.com/v/xxxxxxxxxxxx) i added it to the movie section of the flash object. It is working but only on my computer. If i execute the .exe in any other pc it doesnt work. It says that System.IO.FileNotFoundException.
What can i do to make it work?
I'm trying to embed a youtube video in a winforms application.
When I click I button, a new panel pops up with the video in it and it should play.
However, it doesn't. There's just a black box and nothing happens. Here's what the code looks like for that button:
private void module1_summary_nextpic_Click(object sender, EventArgs e)
{
activePanel.Visible = false;
activePanel = module1_content;
module1_content.Size = module1_panel.Size;
activePanel.Visible = true;
doc1.LoadMovie(0, "http://youtu.be/2Vb8dg_un-A");
doc1.Play();
}
any ideas as to why it's not showing/playing? i'm using vs2012.
edit: i've tried this solution here: https://stackoverflow.com/questions/17666243/calling-play-on-c-sharp-shockwave-component-doesnt-start-youtube-video-playba?rq=1 with no avail.
There is a problem with your link. Link should be like this:
http://www.youtube.com/v/2Vb8dg_un-A
That will make youtube video embbeded. Also, if you want to make it to autoplay just add &autoplay=1 at the end of the link.
Here is my xaml code:
<MediaElement x:Name="beepSound" Source="/Sounds/beep.mp3" AutoPlay="False" Visibility="Collapsed"/>
C# code:
private void ButtonClick(object sender, RoutedEventArgs e)
{
if (beepSound.CurrentState == System.Windows.Media.MediaElementState.Playing)
beepSound.Pause();
else
beepSound.Play();
}
This code works perfectly. But after I resume the app (by pressing start button and then back again into the app) the sound doesn't play. What causes this behavior? Is there anything wrong with my code?
There is nothing wrong in your code
Its just that, Media Element stops working in the background. CurrentState of the media elements gives a "Closed" when we get back to the app after pressing the start button.
You need to use a player that plays the sound even when the app goes in the background(start key press/lock key press). And BackgroundAudioPlayer follows over your requirement.
I am not very much aware with how it works but I can suggest you with some links at this point of time.
Please have a look at the BackgroundAudiolayer
and also its namespace.
And a Sample
Enjoy!
After a bit of research I found out that, after the app resumes it loses its source information. So you have to set the source again. Here is how I did it.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
beepSound.Source = new Uri("/Sounds/beep.mp3", UriKind.Relative);
}