I'm trying to come up with a method of creating a video file (or even an animated gif), using a collection of BitmapImage in a Windows 10 application (UWP). I noticed that the mobile extensions have a ScreenCapture class (I'm not sure if that would do what I need anyway), but I need this to work on desktop as a minimum. I've had a play with the MediaCapture class, but am unable to find any methods that allow me to record images from the screen, or manipulate the video directly.
Windows.Media.Capture.MediaCapture mc = new Windows.Media.Capture.MediaCapture();
mc.StartRecordToStreamAsync()
Is what I'm trying to do possible using UWP in C#, and if so, how?
You'll need MediaComposition API.
var composition = new MediaComposition();
Add clips (files)
composition.Clips.Add(await MediaClip.CreateFromImageFileAsync(someImageFile));
and in the end render to file
await composition.RenderToFileAsync(file);
Related
Is there any way I can play audio in my c#.NET application by using a soundcloud stream URI? I found a method to do this with windows 8 phones:
new AudioTrack(new Uri("[your soundcloud uri]", UriKind.Absolute), "[Track Name]", "[Artist]", "[Album]", null)
But I can't find a method to do this in desktop .NET framework. Could someone shine some light on this?
Since SoundCloud uses mp3 as streaming format, you may use WMPLib. First you need to add reference of it (Project -> References -> Add Reference -> COM -> Windows Media Player)
var wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "http://somewebsite.com/somedir/somefile.mp3";
wplayer.controls.play();
But on computers without Windows Media Player (Like Windows N, KN), you may need third-party libraries to play soundcloud streams. For example, NAudio.
ps: btw, the play of WMPLib is async, so you need to register to StateChange event to know whether the music is ended. See the MSDN Article.
Reference: MSDN Article
In My case I want to play a sound file from a C# class file.
I refer the examples with create Media Element in the xaml page.
I want to play a sound every 5 minutes. This process is behind of my application. I don't have a design page for this.
If your sound is a WAV file, try this:
Stream stream = TitleContainer.OpenStream("sounds/bonk.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
Update
Please, take into account that SoundEffect class lives in Microsoft.Xna.Framework.Audio namespace and is part of the XNA Framework Class Library, which is not supported on Windows Phone 8.1 Runtime apps (not Silverlight one). This means that if you are planning to upgrade/port your application to universal either for Windows Phone 8.1 (and upper) or Windows 8.1 (and upper), this answer will not work for you, unfortunately.
Simply declare your Media Element in code:
MediaElement element = new MediaElement();
We're creating a video player in WPF using .NET 4.0. For this purpose we are using MediaElement. For videos with multiple audio streams, we have MediaElement.AudioStreamIndex property in Silverlight and Windows Store apps. But I didn't find any similar property in WPF. Am I missing something? What's the best way to implement such functionality in WPF?
I am developing a Window7, C#/WPF based GUI and I want to show H.264 video which I get from the RTP stream of a video call. I am using a C based open source library for making the video call. This is what I want to implement: The user dials a URI by typing in the address and pressing the call button and when the video call is established the H.264 stream is seen in the WPF GUI window.
Does the latest WPF support H.264? If not, what other windows based framework/technology can I use to show H.264 video on Windows 7?
Yes, WPF VideoElement can show H264, if you have latest windows media player installed(I think windows7 has WMP installed by default).
If that doesn't benefit you, you can always use MediaKit that can do everything: http://wpfmediakit.codeplex.com/ (you can feed your own DirectShow graph to VideoElement by registering new protocol - basically means anything is possible this way)
How do you integrate a PictureBox to display a video through WPF?
You probably don't want to use PictureBox to display images in WPF because it's a Windows Forms control and therefore suffers from interop limitations.
To display an image in WPF, use the Image element. Set its Source to be, typically, a BitmapImage whose UriSource is the URI of the bitmap file (which might be on the file system). (You can use another ImageSource type if that's an easier way to interface with the webcam.)
To display video, use the MediaElement element. To display a video file, set MediaElement's Source property to the URI of the video (which again might be on the file system). If you need to pull images from the webcam in order to form the video, you need to use the MediaElement in "clock mode," which is described in the MediaElement class topic in MSDN. See also "Multimedia Overview" in the WPF SDK (http://msdn.microsoft.com/en-us/library/aa970915.aspx).
Also try WPF MediaKit. The WPF MediaKit has a VideoCaptureElement control for WebCam support!