كيف يمكنني معاينة جلسة ويندوز ميديا ​​التشفير في برنامج الأغذية العالمي؟

StackOverflow https://stackoverflow.com/questions/280604

سؤال

وتعمل هذه التعليمة البرمجية في تطبيق أشكال النوافذ (فإنه يدل على المعاينة) ولكن ليس في تطبيق WPF.

WMEncoder _encoder;
WMEncDataView _preview;
_encoder = new WMEncoder();

IWMEncSourceGroupCollection SrcGrpColl = _encoder.SourceGroupCollection;
IWMEncSourceGroup2 sourceGroup = (IWMEncSourceGroup2)SrcGrpColl.Add("SG_1");
IWMEncVideoSource2 videoDevice = (IWMEncVideoSource2)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
videoDevice.SetInput("Default_Video_Device", "Device", "");
IWMEncAudioSource audioDevice = (IWMEncAudioSource)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
audioDevice.SetInput("Default_Audio_Device", "Device", "");

IWMEncProfile2 profile = new WMEncProfile2();
profile.LoadFromFile("Recording.prx");
sourceGroup.set_Profile(profile);

_encoder.PrepareToEncode(true);

_preview = new WMEncDataView();
int lpreviewStream = videoDevice.PreviewCollection.Add(_preview);

_encoder.Start();

_preview.SetViewProperties(lpreviewStream, (int)windowsFormsHost1.Handle);
_preview.StartView(lpreviewStream);

ولقد حاولت استخدام عنصر تحكم WindowsFormsHost للحصول على مقبض لتمرير (كما هو موضح في العينة)، ولكن لا يوجد حتى الآن الحظ.

هل كانت مفيدة؟

المحلول

ولقد فعلت شيئا من هذا القبيل في الآونة الأخيرة لدمج عنصر ديريكتشو الفيديو الموجودة مع برنامج الأغذية العالمي واجهة المستخدم الجديدة. وهناك مجموعة متنوعة من الطرق للقيام بذلك، ولكن ربما كان الأسهل هو اشتقاق فئة جديدة من <لأ href = "http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndhost. ASPX "يختلط =" نوفولو noreferrer "> HwndHost . يمكنك بعد ذلك ببساطة تجاوز اثنين من الأساليب، وإعطاء مؤشر الإطار إلى تيار المعاينة وكل شيء يجب أن تعمل فقط. اعتمادا على الاحتياجات الخاصة بك قد تحتاج إلى التعامل مع بضع رسائل Windows في WndProc الخاص للتعامل مع تغيرات العرض وإعادة رسم عندما لا يلعب الفيديو.

using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;

namespace SOQuestion
{
    public class VideoHost : HwndHost
    {
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            IntPtr hwndHost = IntPtr.Zero;
            int hostHeight = (int) this.ActualHeight;
            int hostWidth = (int) this.ActualWidth;

            hwndHost = CreateWindowEx(0, "static", "",
                WS_CHILD | WS_VISIBLE,
                0, 0,
                hostHeight, hostWidth,
                hwndParent.Handle,
                (IntPtr)HOST_ID,
                IntPtr.Zero,
                0);

            return new HandleRef(this, hwndHost);
        }

        protected override void DestroyWindowCore(HandleRef hwnd)
        {
            DestroyWindow(hwnd.Handle);
        }

        protected override void OnWindowPositionChanged(Rect rcBoundingBox)
        {
            base.OnWindowPositionChanged(rcBoundingBox);

            _preview.SetViewProperties(lpreviewStream, (int)this.Handle);
        }

        protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // Handle a couple of windows messages if required - see MSDN for details

            return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
        }

        [DllImport("user32.dll", EntryPoint = "CreateWindowEx", CharSet = CharSet.Auto)]
        internal static extern IntPtr CreateWindowEx(int dwExStyle,
        string lpszClassName,
        string lpszWindowName,
        int style,
        int x, int y,
        int width, int height,
        IntPtr hwndParent,
        IntPtr hMenu,
        IntPtr hInst,
        [MarshalAs(UnmanagedType.AsAny)] object pvParam);

        [DllImport("user32.dll", EntryPoint = "DestroyWindow", CharSet = CharSet.Auto)]
        internal static extern bool DestroyWindow(IntPtr hwnd); 

        internal const int WS_CHILD = 0x40000000;
        internal const int WS_VISIBLE = 0x10000000;
        internal const int HOST_ID = 0x00000002;
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top