My application currently uses the AXWindowsMediaPlayer component to play videos and in turn sound is played using the default sound device.
I need to add support for playing multiple videos and in turn I need to be able to setup audio sources for each of the videos.
Thoughts on how to achieve this:
Set the audio endpoint of the AXWindowsMediaPlayer to my specified device (I Know I can do this in windows media player program but don't know how in code).
Play the video using WMP and stream the audio using NAudio.
Can anyone provide some recommendations on how best to achieve what I need and perhaps a link to some documentation I need to be looking at? I can't seem to find anything on this.
I ended up using NAUDIO for this.
This is the code I used:
var waveReader = new MediaFoundationReader(playListItem.FilePath);
_waveOut = new WaveOut {DeviceNumber = playListItem.PlayerScreen.AudioDevice.Id};
_waveOut.Init(waveReader);
wmPlayer.settings.volume = 0;
wmPlayer.URL = playListItem.FilePath;
_waveOut.Play();
Related
I am currently using VlcControl (2014.4.18.0) to play the video in old
VLC Media player using rtsp Url in c# code
VlcControl _videoControl;
String rtspUrl = networkUrl;
var media = new LocationMedia(rtspUrl);
media.AddOption("rtsp-tcp");
_videoControl.Play(media);
The issue here is, the video is not playing in default Video Track 1 but
it is playing in Video Track 2.
Is there any way to set the Video Track to 2?
Kindly let me know if any options available to set the video track and play.
There is a VideoTracksManagement object that allows you to change the Video track.
I have a mp3 file. I have a background sound file like rain sound or some fire sound. I want to play these two files parallel in the app as well as in background. So that it looks like a single music is playing a story with a background. Please provide any guidance to achieve this.
AFAIK there are four ways to play audio in WP: BackgroundAudioPlayer, MediaElement, SoundEffect, Microsoft Media Foundation. As for your question:
BackgroundAudioPlayer - it won't work, as there is only one Instance of BAP on the phone. So to play a different file, you have to change Track's Source, so it won't handle two at the same time.
MediaElement - it's also a bad idea (it won't also run with BAP simultanously), because as MSDN says:
When a MediaElement control plays audio or video content, any background sounds or media already playing are halted. The app launches the playback experience when the user taps the control. Only one MediaElement control can operate at a time.
you can try to play many sounds using SoundEffect (thougt as Documentation says it can be only a wave file), I won't post code here, because there are already many examples: one, two, three
as for Microsoft Media Foundation: Walkthrough, Programming Guide, Supported file formats
I'd like to be able to press a button to play a sound of a button being pressed while music is already playing. SoundPlayer is no help because it stops the music to play the sound.
I have added the sounds to my Resources (WindowsFormsApplication2.Resources.Properties.button) and I don't want to have to type in the file location.
Answer from MerickOWA
You CANNOT play two sounds at once using SoundPlayer.
SoundPlayer is using the native WINAPI PlaySound function to accomplish the task which has no support for playing simultaneous sounds. Creating multiple instances of SoundPlayer won't help.
There are many options most of which involve implementing a lot of the low level API to window's native audio library or DirectSound (note neither are C# and require alot of interop code)
The simplest option would be to depend on windows media player to play the audio for you.
Add a reference to "C:\Windows\System32\wmp.dll"
then use
var player = new WMPLib.WindowsMediaPlayer();
player.URL = #"..\..\bin\debug\tribal dance.wav";
Note: play starts immediately after setting the URL property
The down side of this approach is your reliance on media player for your application to work properly. On the upside, you can use any file format media player supports.
I want to build application which needs to be able to capture video from a web camera using C#. The captured video should be compressed using some codec (nothing special, anything available that saves space) and written to a file while capturing. A live preview of capture is not necessary.
The first question is: Which API is suitable for this and what would you recommend (I have seen DirectShow, Windows Media Foundation wrapper, etc. I am not sure which is would be best for managed environment and C#)?
I also need a video player in WPF which will play captured video. This player must be able to play captured video from an arbitrary position, pause and start/stop video.
Putting it all together, video is captured from a webcam in the background and at the same time the player plays that video being captured, but it can be paused, re-winded, stopped - something like a modern DVR.
The second question: Is it possible to create such a player using WPF MediaElement? (Confusion is about the file which is at the same time filled from the capture and played in the player)
A nice example of how to make all what you want: WebCam
I have used the AForge set of libraries to accept the videos frame by frame. I used the private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image) function to do this.
I've used VlcDotNet. It is very flexible and simple to use. It has a pretty active user base as well.
I've used it for displaying live video streams as well as recording to files.
You can try the DirectShow.net library.
I can recommend WPF's ffmediaelement. It's built on FFmpeg. So what can FFmpeg, can also ffmediaelement. It can capture video from both the webcam and the capture card. Unlike DirectShow, it's very simple.
Here's how to set up a video source:
Media.Source = new Uri("device://dshow/?video=Osprey-460e Video Device 1C");
... and parameters for it in MediaOpening event:
Media.OnMediaOpening(s, e) =>
{
e.Options.Input["framerate"] = "25";
e.Options.Input["video_size"] = "768x576";
e.Options.Input["pixel_format"] = "yuyv422";
};
I Want to play a song in the background of my WPF Application, but i prefer not using
MediaElement Because it requires MediaPlayer 10 to run, and i can't have control on whether the user will have it or not.
What are my options?
If you do not want to use MediaElement, you can use NAudio to play an MP3.
There are multiple ways to play a Mp3 File in .Net. Try IrrKlang for example which is free for non-comercial usage.
You could also use the C# port of JavaLayer.