Theul Tec
Theul Tec

Reputation: 1

WinUI 3 Camera Preview shows the image but the audio is not played

In my WinUI project I am using the Capture Element / Camera Preview example from the WinUI 3 Gallery app. The image is shown, but the audio is not played. What could be wrong?

Code:

using Windows.Media.Capture.Frames;
using Windows.Media.Capture;

    private MediaFrameSourceGroup mediaFrameSourceGroup;
    private MediaCapture mediaCapture;

    async private void StartCaptureElement()
    {
        var groups = await MediaFrameSourceGroup.FindAllAsync();
        if (groups.Count == 0)
        {
            frameSourceName.Text = "No camera devices found.";
            return;
        }
        mediaFrameSourceGroup = groups.First();

        frameSourceName.Text = "Viewing: " + mediaFrameSourceGroup.DisplayName;
        mediaCapture = new MediaCapture();
        var mediaCaptureInitializationSettings = new MediaCaptureInitializationSettings()
        {
            SourceGroup = this.mediaFrameSourceGroup,
            SharingMode = MediaCaptureSharingMode.SharedReadOnly,
            StreamingCaptureMode = StreamingCaptureMode.Video,
            MemoryPreference = MediaCaptureMemoryPreference.Cpu
        };
        await mediaCapture.InitializeAsync(mediaCaptureInitializationSettings);

        // Set the MediaPlayerElement's Source property to the MediaSource for the mediaCapture.
        var frameSource = mediaCapture.FrameSources[this.mediaFrameSourceGroup.SourceInfos[0].Id];
        captureElement.Source = Windows.Media.Core.MediaSource.CreateFromMediaFrameSource(frameSource);
    }

I tried using the example code by changing: StreamingCaptureMode = StreamingCaptureMode.Video for StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo but I was unsuccessful.

Upvotes: 0

Views: 65

Answers (0)

Related Questions