Example #1
0
        public MainPage()
        {
            this.InitializeComponent();

            var protectionManager = new MediaProtectionManager();

            //A setting to tell MF that we are using PlayReady.
            var props = new Windows.Foundation.Collections.PropertySet();

            props.Add("{F4637010-03C3-42CD-B932-B48ADF3A6A54}", "Windows.Media.Protection.PlayReady.PlayReadyWinRTTrustedInput");
            protectionManager.Properties.Add("Windows.Media.Protection.MediaProtectionSystemIdMapping", props);
            protectionManager.Properties.Add("Windows.Media.Protection.MediaProtectionSystemId", "{F4637010-03C3-42CD-B932-B48ADF3A6A54}");

            //Maps the container guid from the manifest or media segment
            protectionManager.Properties.Add("Windows.Media.Protection.MediaProtectionContainerGuid", "{9A04F079-9840-4286-AB92-E65BE0885F95}");

            protectionManager.ServiceRequested    += ProtectionManager_ServiceRequested;
            protectionManager.ComponentLoadFailed += ProtectionManager_ComponentLoadFailed;

            // media player
            MediaPlayer mediaPlayer = new MediaPlayer();

            mediaPlayer.MediaOpened += MediaPlayer_MediaOpened;
            mediaPlayer.MediaFailed += MediaPlayer_MediaFailed;

            // media source
#if true
            AudioEncodingProperties audioProperties = AudioEncodingProperties.CreateAacAdts(44100, 1, 72000);
            Guid MF_SD_PROTECTED = new Guid(0xaf2181, 0xbdc2, 0x423c, 0xab, 0xca, 0xf5, 0x3, 0x59, 0x3b, 0xc1, 0x21);
            //audioProperties.Properties.Add(MF_SD_PROTECTED, 1 /* true ? doc says UINT32 - treat as a boolean value */);
            audioProperties.Properties.Add(MF_SD_PROTECTED, PropertyValue.CreateUInt32(1));
            AudioStreamDescriptor audioStreamDescriptor = new AudioStreamDescriptor(audioProperties);
            foreach (var prop in audioStreamDescriptor.EncodingProperties.Properties)
            {
                Log(prop.Key.ToString() + " => " + prop.Value.ToString());
            }
            MediaStreamSource mediaStreamSource = new MediaStreamSource(audioStreamDescriptor);
            mediaStreamSource.MediaProtectionManager = protectionManager;   // protection manager is on the media stream source
            mediaStreamSource.SampleRequested       += MediaStreamSource_SampleRequested;
            mediaStreamSource.Starting += MediaStreamSource_Starting;
            MediaSource mediaSource = MediaSource.CreateFromMediaStreamSource(mediaStreamSource);
#else
            MediaSource mediaSource = MediaSource.CreateFromUri(new Uri("http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)"));
            mediaPlayer.ProtectionManager = protectionManager;              // protection manager is on the media player
#endif

            // play !
            m_mediaPlayerElement.SetMediaPlayer(mediaPlayer);
            mediaPlayer.Source = mediaSource;
            mediaPlayer.Play();
        }
Example #2
0
        public static object Parse(AppDataType.Type type, string s)
        {
            object obj = null;

            switch (type)
            {
            case AppDataType.Type.Empty: obj = PropertyValue.CreateEmpty();; break;

            case AppDataType.Type.UInt8: obj = PropertyValue.CreateUInt8(s.IsEmpty() ? (byte)0 : Byte.Parse(s)); break;

            case AppDataType.Type.Int16: obj = PropertyValue.CreateInt16(s.IsEmpty() ? (short)0 : Int16.Parse(s)); break;

            case AppDataType.Type.UInt16: obj = PropertyValue.CreateUInt16(s.IsEmpty() ? (ushort)0 : UInt16.Parse(s)); break;

            case AppDataType.Type.Int32: obj = PropertyValue.CreateInt32(s.IsEmpty() ? 0 : Int32.Parse(s)); break;

            case AppDataType.Type.UInt32: obj = PropertyValue.CreateUInt32(s.IsEmpty() ? 0 : UInt32.Parse(s)); break;

            case AppDataType.Type.Int64: obj = PropertyValue.CreateInt64(s.IsEmpty() ? 0 : Int64.Parse(s)); break;

            case AppDataType.Type.UInt64: obj = PropertyValue.CreateUInt64(s.IsEmpty() ? 0 : UInt64.Parse(s)); break;

            case AppDataType.Type.Single: obj = PropertyValue.CreateSingle(s.IsEmpty() ? 0 : Single.Parse(s)); break;

            case AppDataType.Type.Double: obj = PropertyValue.CreateDouble(s.IsEmpty() ? 0 : Double.Parse(s)); break;

            case AppDataType.Type.Char16: obj = PropertyValue.CreateChar16(Char.Parse(s)); break;

            case AppDataType.Type.Boolean: obj = PropertyValue.CreateBoolean(s.IsEmpty() ? false : Boolean.Parse(s)); break;

            case AppDataType.Type.String: obj = s; break;

            default: break;
            }
            return(obj);
        }
        public async void StartRecord(string label, uint quality)
        {
            try
            {
                if (mode == RecordMode.AUDIO)
                {
                    StorageFile file = await videoStore.CreateFileAsync($"{label}.mp3", CreationCollisionOption.GenerateUniqueName);

                    await MediaCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), file);
                }
                else if (mode == RecordMode.VIDEO || mode == RecordMode.VIDEOAUDIO)
                {
                    // Choose quality based recording
                    MediaCap.SetEncoderProperty(MediaStreamType.VideoRecord, new Guid(0x1c0608e9, 0x370c, 0x4710, 0x8a, 0x58, 0xcb, 0x61, 0x81, 0xc4, 0x24, 0x23), PropertyValue.CreateUInt32(3));
                    // Set quality level
                    MediaCap.SetEncoderProperty(MediaStreamType.VideoRecord, new Guid(0xfcbf57a3, 0x7ea5, 0x4b0c, 0x96, 0x44, 0x69, 0xb4, 0x0c, 0x39, 0xc3, 0x91), PropertyValue.CreateUInt32(quality));

                    StorageFile file = await videoStore.CreateFileAsync($"{label}.mp4", CreationCollisionOption.GenerateUniqueName);

                    await MediaCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file);
                }
                else
                {
                    IsRecording = false;
                }
                IsRecording = true;
                Log.Error("Began Recording");
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to record:\t{ex}");
            }
        }
Example #4
0
        private async Task StartPreviewAsync()
        {
            try
            {
                m_mediaCapture = new MediaCapture();

                m_mediaCapture.Failed += OnMediaCaptureFailed;

                _displayRequest.RequestActive();

                // Populate orientation variables with the current state
                m_displayOrientation = m_displayInformation.CurrentOrientation;

                RegisterEventHandlers();

                m_mediaCapture.RecordLimitationExceeded += OnMediaCaptureRecordLimitationExceeded;

                var devInfo = await FindCameraDeviceByPanelAsync(m_desiredCameraPanel);

                var id = devInfo != null ? devInfo.Id : string.Empty;

                var settings = new MediaCaptureInitializationSettings();
                settings.VideoDeviceId = id;
                settings.MediaCategory = MediaCategory.Communications;

                await m_mediaCapture.InitializeAsync(settings);

                m_mediaCapture.SetEncoderProperty(MediaStreamType.VideoPreview, new Guid("9C27891A-ED7A-40e1-88E8-B22727A024EE"), PropertyValue.CreateUInt32(1));

                var resolutionMax = GetHighestResolution();

                ImageWidth  = resolutionMax.Width;
                ImageHeight = resolutionMax.Height;

                await m_mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, resolutionMax);

                m_PreviewVideoElement.Source = m_mediaCapture;
                await AddEffectsAsync();

                await m_mediaCapture.StartPreviewAsync();

                await SetPreviewRotationAsync();

                IsCaptureEnabled = true;

                UpdateButtonState();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }