当前位置: 首页>>代码示例>>C#>>正文


C# MediaElement.SetSource方法代码示例

本文整理汇总了C#中System.Windows.Controls.MediaElement.SetSource方法的典型用法代码示例。如果您正苦于以下问题:C# MediaElement.SetSource方法的具体用法?C# MediaElement.SetSource怎么用?C# MediaElement.SetSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.MediaElement的用法示例。


在下文中一共展示了MediaElement.SetSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetSourceAsync

        public Task SetSourceAsync(IMediaStreamSource source)
        {
            return Dispatch(() =>
            {
                source.ValidateEvent(MediaStreamFsm.MediaEvent.MediaStreamSourceAssigned);

                var wasSet = Interlocked.Exchange(ref _sourceIsSet, 1);

                Debug.Assert(0 == wasSet);

                if (null != _mediaElement)
                {
                    UiThreadCleanup();

                    var mediaElement = _mediaElement;
                    _mediaElement = null;

                    _destroyMediaElement(mediaElement);
                }

                _mediaElement = _createMediaElement();

                if (null != _mediaElement)
                    _mediaElement.SetSource((MediaStreamSource)source);
                else
                    Debug.WriteLine("MediaElementManager.SetSourceAsync() null media element");
            });
        }
开发者ID:Jesn,项目名称:MangGuoTv,代码行数:28,代码来源:MediaElementManager.cs

示例2: Play

 internal void Play(float volume)
 {
     //Creating and setting source within constructor starts
     //playing song immediately.
     song = new MediaElement();
     song.MediaEnded += new RoutedEventHandler(song_MediaEnded);
     _graphics.Root.Children.Add(song);
     song.SetSource(resourceInfo.Stream);
     song.Volume = volume;
     song.Play();
 }
开发者ID:liwq-net,项目名称:SilverSprite,代码行数:11,代码来源:Song.cs

示例3: LoadMedia

        public static void LoadMedia(string key)
        {
            Uri uri = new Uri(string.Format("XamlTetris;component/{0}", key), UriKind.Relative);
            StreamResourceInfo sri = System.Windows.Application.GetResourceStream(uri);

            MediaElement element = new MediaElement();
            element.AutoPlay = false;
            element.Visibility = Visibility.Collapsed;
            element.SetSource(sri.Stream);
            rootPanel.Children.Add(element);

            mediaElements.Add(key, element);
        }
开发者ID:bramom,项目名称:XTetris,代码行数:13,代码来源:SoundUtility.cs

示例4: Initialize

 private void Initialize() {
   _Frequencies = TestFrequencies.GetFrequencies();
   _generator = new OscillationSoundWave() { SoundWaveData = _Frequencies };
   _MediaElement = new MediaElement() { AutoPlay = false };
   _MediaElement.SetSource(_generator.Source);
   _currentIndex = 0;
   _Timer = new DispatcherTimer();
   _Timer.Interval = new TimeSpan( 0, 0, 1 );
   _Timer.Tick += _Timer_Tick;
   //_Track.PropertyChanged += _Track_PropertyChanged;
   _StartCommand = new SimpleCommand();
   _StartCommand.Executed += TestFrequenciesViewModel_Executed;
   _StartCommand.MayBeExecuted = true;
 }
开发者ID:cmcginn,项目名称:MHFinance,代码行数:14,代码来源:TestFrequenciesViewModel.cs

示例5: Application

 public Application()
 {
     this.Startup += delegate {
         this.RootVisual = new Canvas();
         this.Canvas.Loaded += delegate {
             MediaElement audioElement = new MediaElement();
             this.Canvas.Children.Clear();
             this.Canvas.Children.Add(audioElement);
             this.Canvas.Children.Add(new Canvas());
             audioElement.SetSource(this.GetType().Assembly.GetManifestResourceStream("Monotone.Monotone.mp3"));
             audioElement.MediaOpened += delegate {
                 this.NextPart();
                 this.timer.Interval = new TimeSpan(0, 0, 0, 0, (int)((60f / 140f) * 4 * 4 * 2 * 1000f));
                 this.timer.Tick += delegate {
                     this.timer.Stop();
                     this.NextPart();
                     this.timer.Start();
                 };
                 this.timer.Start();
             };
         };
     };
 }
开发者ID:modulexcite,项目名称:Monotone,代码行数:23,代码来源:Application.cs

示例6: S_StartSound

        // =======================================================================
        // Start a sound effect
        // =======================================================================
        public static void S_StartSound(int entnum, int entchannel, sfx_t sfx, double[] origin, double fvol, double attenuation)
        {
            channel_t   target_chan, check;
            sfxcache_t	sc;
            int		    vol;
            int		    ch_idx;
            int		    skip;

            /*if (entnum != 195)
                return;*/

            if (sound_started == 0)
                return;

            if (sfx == null)
                return;

            if (nosound.value != 0)
                return;

            vol = (int)(fvol*255);

            // pick a channel to play on
            target_chan = SND_PickChannel(entnum, entchannel);
            if (target_chan == null)
                return;

            // spatialize
            mathlib.VectorCopy(origin, ref target_chan.origin);
            target_chan.dist_mult = attenuation / sound_nominal_clip_dist;
            target_chan.master_vol = vol;
            target_chan.entnum = entnum;
            target_chan.entchannel = entchannel;
            SND_Spatialize(target_chan);

            if (target_chan.leftvol == 0 && target_chan.rightvol == 0)
                return;		// not audible at all

            // new channel
            sc = S_LoadSound (sfx);
            if (sc == null)
            {
                target_chan.sfx = null;
                return;		// couldn't load the sound's data
            }

            target_chan.sfx = sfx;

            /*            if (sc.loopstart != -1)
                console.Con_Printf(sfx.name + " " + entnum + " " + entchannel + "\n");*/

            MediaElement media = new MediaElement();
            target_chan.media = media;
            media.AutoPlay = true;
            media.SetSource(new MemoryStream(sc.data));
            media.Tag = target_chan;
            /*if (sc.loopstart != -1)
            {
                media.MediaEnded += media_MediaEnded;
                target_chan.looping = 1;
            }
            else*/
                media.MediaEnded += media_MediaEnded2;
            SetVolume(target_chan);
            Page.thePage.parentCanvas.Children.Add(media);
        }
开发者ID:rodrigobrito,项目名称:quakelight,代码行数:69,代码来源:snd_dma.cs

示例7: OnNavigatedTo

        /// <summary>
        /// If camera has not been initialized when navigating to this page, initialization
        /// will be started asynchronously in this method. Once initialization has been
        /// completed the camera will be set as a source to the VideoBrush element
        /// declared in XAML. On-screen controls are enabled when camera has been initialized.
        /// </summary>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (Camera != null)
            {
                Camera.Dispose();
                Camera = null;
            }

            ShowProgress(AppResources.InitializingCameraText);
            await InitializeCamera(PerfectCamera.DataContext.Instance.SensorLocation);
            HideProgress();

            InitEffectPanel();

            if (PerfectCamera.DataContext.Instance.CameraType == PerfectCameraType.Selfie)
            {
                _mediaElement = new MediaElement { Stretch = Stretch.UniformToFill, BufferingTime = new TimeSpan(0) };
                _mediaElement.SetSource(_cameraStreamSource);

                BackgroundVideoBrush.SetSource(_mediaElement);

                EffectNameTextBlock.Text = _cameraEffect.EffectName;
                EffectNameFadeIn.Begin();
            }
            else
            {
                BackgroundVideoBrush.SetSource(Camera);
            }

            SetScreenButtonsEnabled(true);
            SetCameraButtonsEnabled(true);
            Storyboard sb = (Storyboard)Resources["CaptureAnimation"];
            sb.Stop();

            SetOrientation(this.Orientation);

            base.OnNavigatedTo(e);
        }
开发者ID:KayNag,项目名称:LumiaImagingSDKSample,代码行数:44,代码来源:CameraPage.xaml.cs

示例8: Initialize

        private async Task Initialize()
        {


            var resolution = PhotoCaptureDevice.GetAvailableCaptureResolutions(_cameraLocation).First();

            _photoCaptureDevice = await PhotoCaptureDevice.OpenAsync(_cameraLocation, resolution);

            Windows.Foundation.Size PreviewResolution;
            foreach (var res in PhotoCaptureDevice.GetAvailablePreviewResolutions(_cameraLocation).ToArray().Reverse())
            {
                try
                {
                    await _photoCaptureDevice.SetPreviewResolutionAsync(res);
                    PreviewResolution = res;
                    break;

                }
                catch (Exception e)
                {
                }
            }



            _cameraStreamSource = new CameraStreamSource(_photoCaptureDevice, PreviewResolution);

            _mediaElement = new MediaElement();
            _mediaElement.BufferingTime = new TimeSpan(0);
            _mediaElement.SetSource(_cameraStreamSource);

            // Using VideoBrush in XAML instead of MediaElement, because otherwise
            // CameraStreamSource.CloseMedia() does not seem to be called by the framework:/

            BackgroundVideoBrush.SetSource(_mediaElement);



            AdjustOrientation();
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:40,代码来源:LIve.xaml.cs

示例9: SetSource_StreamNull

		public void SetSource_StreamNull ()
		{
			MediaElement media = new MediaElement ();
			media.MediaFailed += delegate { /* do nothing */ };

			Assert.IsNull (media.Source, "Source-1");

			media.SetSource (Stream.Null);
			Assert.IsNull (media.Source, "Source-2");

			media.Source = new Uri ("thisfinedoesnotexist.wmv", UriKind.Relative);
			Assert.IsNotNull (media.Source, "Source-3");

			media.SetSource (Stream.Null);
			Assert.IsNull (media.Source, "Source-4");
		}
开发者ID:dfr0,项目名称:moon,代码行数:16,代码来源:MediaElementTest.cs

示例10: ThreadPool

		public void ThreadPool ()
		{
			int tid = Thread.CurrentThread.ManagedThreadId;
			bool opened = false;
			OpenMediaOnSameThread = false;
			CloseMediaOnSameThread = false;

			Enqueue (() => {
				Assert.AreEqual (tid, Thread.CurrentThread.ManagedThreadId, "Different thread ids");

				MediaStreamSourceBase mss = new MediaStreamSourceBase ();
				mss.InitializeSource (true, 5000000);
				mss.AddVideoStream ();

				MediaElement mel = new MediaElement ();
				mel.MediaOpened += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) {
					opened = true;
					Assert.AreEqual (tid, Thread.CurrentThread.ManagedThreadId, "MediaOpened");
				});
				mel.SetSource (mss);
#if false
				Assert.Throws<InvalidOperationException> (delegate {
					mel.SetSource (mss); // 2nd SetSource to get a Close event
				}, "Close");
#endif
				TestPanel.Children.Add (mel);
			});
			EnqueueConditional (() => opened);
			Enqueue (delegate () {
				Assert.IsTrue (OpenMediaOnSameThread, "OpenMediaOnSameThread");
//				Assert.IsTrue (CloseMediaOnSameThread, "CloseMediaOnSameThread");
			});
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:34,代码来源:MediaStreamSourceTest.cs

示例11: CN1Media

 public CN1Media(Stream s, string mime, java.lang.Runnable onComplete)
 {
     System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         elem = new MediaElement();
         elem.SetSource(s);
         video = true;
         this.onComplete = onComplete;
         elem.MediaEnded += elem_MediaEnded;
     });
 }
开发者ID:mehulsbhatt,项目名称:CodenameOne,代码行数:11,代码来源:SilverlightImplementation.cs

示例12: UserThread

		public void UserThread ()
		{
			int tid = Thread.CurrentThread.ManagedThreadId;
			bool opened = false;
			// set them to true to make sure we're not checking the default (false) value later
			OpenMediaOnSameThread = true;
			CloseMediaOnSameThread = true;

			Dispatcher dispatcher = TestPanel.Dispatcher;

			Thread t = new Thread (delegate () {
				Assert.AreNotEqual (tid, Thread.CurrentThread.ManagedThreadId, "Same thread ids");

				MediaStreamSourceBase mss = new MediaStreamSourceBase ();
				mss.InitializeSource (false, 5000000);
				mss.AddVideoStream ();

				dispatcher.BeginInvoke (delegate {
					MediaElement mel = new MediaElement ();
					mel.MediaOpened += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e) {
						opened = true;
						Assert.AreEqual (tid, Thread.CurrentThread.ManagedThreadId, "MediaOpened");
					});
					mel.SetSource (mss);
#if false
					Assert.Throws<InvalidOperationException> (delegate {
						mel.SetSource (mss); // 2nd SetSource to get a Close event
					}, "Close");
#endif
					TestPanel.Children.Add (mel);
				});
			});
			t.Start ();
			EnqueueConditional (() => opened);
			Enqueue (delegate () {
				Assert.IsFalse (OpenMediaOnSameThread, "OpenMediaOnSameThread");
//				Assert.IsFalse (CloseMediaOnSameThread, "CloseMediaOnSameThread");
			});
			EnqueueTestComplete ();
		}
开发者ID:dfr0,项目名称:moon,代码行数:40,代码来源:MediaStreamSourceTest.cs

示例13: Initialize

        /// <summary>
        /// Opens and sets up the camera if not already. Creates a new
        /// CameraStreamSource with an effect and shows it on the screen via
        /// the media element.
        /// </summary>
        private async void Initialize()
        {
            Size mediaElementSize = new Size(MediaElementWidth, MediaElementHeight);

            if (camera == null)
            {
                // Resolve the capture resolution and open the camera
                var captureResolutions =
                    PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);

                Size selectedCaptureResolution =
                    captureResolutions.Where(
                        resolution => Math.Abs(AspectRatio - resolution.Width / resolution.Height) <= 0.1)
                            .OrderBy(resolution => resolution.Width).Last();

                camera = await PhotoCaptureDevice.OpenAsync(
                    CameraSensorLocation.Back, selectedCaptureResolution);

                // Set the image orientation prior to encoding
                camera.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation,
                    camera.SensorLocation == CameraSensorLocation.Back
                    ? camera.SensorRotationInDegrees : -camera.SensorRotationInDegrees);

                // Resolve and set the preview resolution
                var previewResolutions =
                    PhotoCaptureDevice.GetAvailablePreviewResolutions(CameraSensorLocation.Back);

                Size selectedPreviewResolution =
                    previewResolutions.Where(
                        resolution => Math.Abs(AspectRatio - resolution.Width / resolution.Height) <= 0.1)
                            .Where(resolution => (resolution.Height >= mediaElementSize.Height)
                                   && (resolution.Width >= mediaElementSize.Width))
                                .OrderBy(resolution => resolution.Width).First();

                await camera.SetPreviewResolutionAsync(selectedPreviewResolution);

                cameraEffect.CaptureDevice = camera;
            }


            if (mediaElement == null)
            {
                mediaElement = new MediaElement();
                mediaElement.Stretch = Stretch.UniformToFill;
                mediaElement.BufferingTime = new TimeSpan(0);
                mediaElement.Tap += OnMyCameraMediaElementTapped;
                source = new CameraStreamSource(cameraEffect, mediaElementSize);
                mediaElement.SetSource(source);
                MediaElementContainer.Children.Add(mediaElement);
                
            } 
            
            // Show the index and the name of the current effect
            if (cameraEffect is NokiaSketchEffect)
            {
                NokiaSketchEffect effects = cameraEffect as NokiaSketchEffect;
            }
            
        }
开发者ID:ghstshdw,项目名称:PaperPhoto,代码行数:64,代码来源:MainPage.xaml.cs

示例14: S_StaticSound

        /*
        =================
        S_StaticSound
        =================
        */
        public static void S_StaticSound(sfx_t sfx, double[] origin, double vol, double attenuation)
        {
            channel_t	ss;
            sfxcache_t  sc;

            if (sfx == null)
                return;

            if (total_channels == MAX_CHANNELS)
            {
                console.Con_Printf ("total_channels == MAX_CHANNELS\n");
                return;
            }

            ss = channels[total_channels];
            total_channels++;

            sc = S_LoadSound (sfx);
            if (sc == null)
                return;

            if (sc.loopstart == -1)
            {
                console.Con_Printf ("Sound " + sfx.name + " not looped\n");
                return;
            }

            ss.sfx = sfx;
            mathlib.VectorCopy (origin, ref ss.origin);
            ss.master_vol = (int)vol;
            ss.dist_mult = (attenuation/64) / sound_nominal_clip_dist;

            SND_Spatialize (ss);

            MediaElement media = new MediaElement();
            ss.media = media;
            media.AutoPlay = true;
            media.SetSource(new MemoryStream(sc.data));
            media.Tag = ss;
            media.MediaEnded += media_MediaEnded;
            SetVolume(ss);
            Page.thePage.parentCanvas.Children.Add(media);
        }
开发者ID:rodrigobrito,项目名称:quakelight,代码行数:48,代码来源:snd_dma.cs

示例15: Test

		private void Test (MediaElement mel, string value, bool can_seek)
		{
			MediaStreamSourceBase mss;

			Enqueue (delegate ()
			{
				mediafailed = false;
				mediaopened = false;
				mss = new MediaStreamSourceBase ();
				mss.InitializeSource (value, "5000000");
				mss.AddVideoStream ();
				mel.Tag = value;
				mel.SetSource (mss);
			});
			EnqueueConditional (() => mediafailed || mediaopened);
			Enqueue (delegate ()
			{
				Assert.AreEqual (can_seek, mel.CanSeek, "CanSeek: " + (string) mel.Tag);
			});
		}
开发者ID:shana,项目名称:moon,代码行数:20,代码来源:MediaStreamSourceTest.cs


注:本文中的System.Windows.Controls.MediaElement.SetSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。