本文整理汇总了C#中System.Windows.Controls.MediaElement.Play方法的典型用法代码示例。如果您正苦于以下问题:C# MediaElement.Play方法的具体用法?C# MediaElement.Play怎么用?C# MediaElement.Play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.MediaElement
的用法示例。
在下文中一共展示了MediaElement.Play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDuration
public static Duration GetDuration(string fileName)
{
Duration naturalDuration = Duration.Automatic;
Window w = new Window
{
Content = _videoElement = new MediaElement() { IsMuted = true },
IsHitTestVisible = false,
Width = 0,
Height = 0,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false,
ShowActivated = false
};
_videoElement.MediaOpened += (sender, args) =>
{
naturalDuration = _videoElement.NaturalDuration;
_videoElement.Close();
w.Close();
};
_videoElement.LoadedBehavior = MediaState.Manual;
_videoElement.UnloadedBehavior = MediaState.Manual;
_videoElement.Source = new Uri(fileName);
_videoElement.Play();
w.ShowDialog();
return naturalDuration;
}
示例2: PlayVideo
public void PlayVideo(string path)
{
MediaElement player = new MediaElement();
player.Source = new Uri(path);
player.AutoPlay = true;
player.Play();
}
示例3: enemyMissile
public enemyMissile(double left, double top)
{
// use this to create the missile on the fly.
// calling function is going to supply the
// X Y Coordinate to create at.
// set up a rectangle
// fill in the values - background, picture,
StackPanel panel = new StackPanel();
Rectangle missileRect = new Rectangle();
missileRect.Height = 3;
missileRect.Width = 12;
missileRect.Fill = new SolidColorBrush(Colors.Black );
missileRect.Stroke = new SolidColorBrush(Colors.Yellow);
missileRect.RadiusX = 1;
missileRect.RadiusY = 1;
panel.Children.Add(missileRect);
MediaElement me = new MediaElement();
me.Source = new Uri("/laser.mp3", UriKind.Relative);
panel.Children.Add(me);
this.Content = panel;
Canvas.SetTop(this, top);
Canvas.SetLeft(this, left);
me.Play();
}
示例4: 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();
}
示例5: TagVisualization3_Loaded
private void TagVisualization3_Loaded(object sender, RoutedEventArgs e)
{
//TODO: customize TagVisualization3's UI based on this.VisualizedTag here
base.OnInitialized(e);
// Query the registry to find out where the sample media is stored.
const string shellKey =
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Folders";
string videosPath =
(string)Microsoft.Win32.Registry.GetValue(shellKey, "CommonVideo", null) + @"\Sample Videos";
// The name of the video.
string targetVideo = @"C:\Users\hcilab\Desktop\Polina\CS320HW2Media\greece.mp4";
// string targetVideo = @"Wildlife.wmv";
// Create a ScatterViewItem control and add it to the Items collection.
ScatterViewItem item = new ScatterViewItem();
videoScatter.Items.Add(item);
// Create a MediaElement object.
MediaElement video = new MediaElement();
video.LoadedBehavior = MediaState.Manual;
video.UnloadedBehavior = MediaState.Manual;
// The media dimensions are not available until the MediaOpened event.
video.MediaOpened += delegate
{
// Size the ScatterViewItem control according to the video size.
item.Height = video.NaturalVideoHeight / 2;
item.Width = video.NaturalVideoWidth / 2;
};
// Set the Content to the video.
item.Content = video;
// Get the video if it exists.
if (System.IO.File.Exists(targetVideo))
{
video.Source = new Uri(targetVideo);
video.Play();
}
else
{
item.Content = "Video not found";
}
}
示例6: Game
// constructor
public Game(UniformGrid g, Label label, StackPanel panel)
{
// TODO
grid = g;
titleLabel = label;
stackPanel = panel;
soundElement = InitializeMediaElement();
stackPanel.Children.Add(soundElement);
soundElement.Play();
board = new Tile[grid.Rows, grid.Columns];
CreateBoard();
AddToGrid();
}
示例7: LADSVideoBubble
public LADSVideoBubble(String filename, double width, double height)
{
_filename = filename;
_video = new MediaElement();
_controls = new VideoItem();
_sliderTimer = new DispatcherTimer();
_preferredSize = new Size(width, height);
_layoutRoot = new Grid();
_video.MediaOpened += new RoutedEventHandler(video_MediaOpened);
_video.MediaEnded += new RoutedEventHandler(video_MediaEnded);
_video.ScrubbingEnabled = true;
_video.LoadedBehavior = MediaState.Manual;
_video.Source = new Uri(_filename, UriKind.RelativeOrAbsolute);
//fire the MediaOpened event
_video.Play();
_video.Pause();
_controls.HorizontalAlignment = HorizontalAlignment.Center;
_controls.VerticalAlignment = VerticalAlignment.Center;
_controls.Hide();
_controls.playButton.Click += new RoutedEventHandler(playButton_Click);
_controls.stopButton.Click += new RoutedEventHandler(stopButton_Click);
_controls.videoSlider.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonDown);
_controls.videoSlider.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonUp);
_controls.videoSlider.PreviewTouchDown += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchDown);
_controls.videoSlider.PreviewTouchUp += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchUp);
_controls.videoSlider.IsMoveToPointEnabled = false;
_controls.videoSlider.SmallChange = 0;
_controls.videoSlider.LargeChange = 0;
_sliderTimer.Interval = new TimeSpan(0, 0, 0, 0, SLIDER_TIMER_RESOLUTION);
_sliderTimer.Tick += new EventHandler(sliderTimer_Tick);
_layoutRoot.RowDefinitions.Add(new RowDefinition());
_layoutRoot.RowDefinitions.Add(new RowDefinition());
_layoutRoot.RowDefinitions[1].Height = new GridLength(50);
Grid.SetRow(_controls, 1);
Grid.SetRow(_video, 0);
_layoutRoot.Children.Add(_video);
this.AddChild(_layoutRoot);
//this.MouseEnter += new MouseEventHandler(VideoBubble_MouseEnter);
//this.MouseLeave += new MouseEventHandler(VideoBubble_MouseLeave);
this.SizeChanged += new SizeChangedEventHandler(LADSVideoBubble_SizeChanged);
}
示例8: PlayMedia
public static void PlayMedia(MediaElement mediaElement, MediaSource mediaSource)
{
try
{
if (mediaSource != null && mediaSource.Uri != null)
{
mediaElement.Stop();
mediaElement.Source = mediaSource.Uri;
mediaElement.Play();
}
}
catch (Exception ex)
{
Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "ManagerConsole.Helper.MediaManager:.\r\n{0}", ex.ToString());
}
}
示例9: MainWindow
// Constructor takes a list of heroes, bgm, and titleScreen
public MainWindow(Hero[] h, MediaElement song, Window create)
{
music = song;
main = create;
music.Source = new Uri("../../Menu.wav", UriKind.Relative);
music.Play();
InitializeComponent();
//Sets the level/campus building's hoverOver statusmain = title;
buildingSetUp();
//Apply all five buttons to the MouseLeave event handler
//When a the mouse leaves one of the five character buttons the button should be set to hidden
btnCharacter1.MouseLeave += character_MouseLeave;
btnCharacter2.MouseLeave += character_MouseLeave;
btnCharacter3.MouseLeave += character_MouseLeave;
btnCharacter4.MouseLeave += character_MouseLeave;
btnCharacter5.MouseLeave += character_MouseLeave;
//Gives setOfHeroes array with passed array of Characters
for (int i = 0; i < h.Length; i++)
{
setOfHeroes[i] = h[i];
}
// places the heroes boardgame picture on the map.
character1image.Source = setOfHeroes[0].CharacterPicture;
character2image.Source = setOfHeroes[1].CharacterPicture;
character3image.Source = setOfHeroes[2].CharacterPicture;
character4image.Source = setOfHeroes[3].CharacterPicture;
character5image.Source = setOfHeroes[4].CharacterPicture;
if (music.IsMuted)
{
Style red = Sound_Off_Button.Style; // holds the red button style from the off button.
Style black = Sound_On_Button.Style; // holds the blank button style from the on button.
// swaps color styles with on and off.
Sound_On_Button.Style = red;
Sound_Off_Button.Style = black;
}
}
示例10: playForDuration
public static void playForDuration(Canvas parent, String filename, TimeSpan startPosition, TimeSpan duration)
{
MediaElement songMediaElement = new MediaElement();
parent.Children.Add(songMediaElement);
songMediaElement.LoadedBehavior = MediaState.Manual;
songMediaElement.Volume = 100;
songMediaElement.Source = new Uri(@"" + filename, UriKind.RelativeOrAbsolute);
var dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler((object sender, EventArgs e) =>
{
songMediaElement.Stop();
(sender as DispatcherTimer).Stop();
parent.Children.Remove(songMediaElement);
});
dispatcherTimer.Interval = duration;
songMediaElement.Position = startPosition;
songMediaElement.Play();
dispatcherTimer.Start();
}
示例11: PlayMedia
public static void PlayMedia(MediaElement mediaElement, TimeSpan start, TimeSpan length, bool muted)
{
mediaElement.Stop();
mediaElement.Position = start;
mediaElement.IsMuted = muted;
Console.WriteLine("Playing video at {0}", start);
mediaElement.Play();
DispatcherTimer timer = null;
n++;
int x = n;
timer = new DispatcherTimer(length, DispatcherPriority.Send,
(_s, _e) => {
if (x == n) {
mediaElement.Pause();
timer.Stop();
}
},
mediaElement.Dispatcher);
}
示例12: OpenMedia
public void OpenMedia(Media item) {
this.Item = item;
TitleText.Text = Item.Title;
TitleText.ToolTip = Item.Title;
player = new MediaElement();
player.LoadedBehavior = MediaState.Manual;
player.UnloadedBehavior = MediaState.Manual;
player.MediaEnded += player_MediaEnded;
player.IsMuted = true;
player.Source = new Uri(Settings.NaturalGroundingFolder + Item.FileName);
player.Position = TimeSpan.FromSeconds(Item.StartPos.HasValue ? Item.StartPos.Value : 0);
player.Play();
viewer = ImageViewerWindow.Instance(player);
viewer.Closed += viewer_Closed;
positionTimer = new DispatcherTimer();
positionTimer.Interval = TimeSpan.FromSeconds(1);
positionTimer.Tick += positionTimer_Tick;
positionTimer.Start();
}
示例13: PlayVideoFullscreenOnUIThread
/// <summary>
/// Creates a native Windows Phone MediaElement and immediatly starts playback.
/// </summary>
/// <param name="videoUrl">URL to the vidoe (from Windows Phone's point of view)</param>
/// <param name="tapSkipsVideo">If true, a tap will stop & remove the Video playback</param>
private static void PlayVideoFullscreenOnUIThread(string videoUrl, bool tapSkipsVideo)
{
#if WINDOWS_PHONE
var frame = Application.Current.RootVisual as PhoneApplicationFrame;
var currentPage = frame.Content as PhoneApplicationPage;
DrawingSurfaceBackgroundGrid drawingSurfaceBackgroundElement = (DrawingSurfaceBackgroundGrid)currentPage.FindName("DrawingSurfaceBackground");
MediaElement videoPlayBackElement = new MediaElement();
videoPlayBackElement.Height = Double.NaN;
videoPlayBackElement.Width = Double.NaN;
videoPlayBackElement.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
videoPlayBackElement.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
videoPlayBackElement.Stretch = System.Windows.Media.Stretch.UniformToFill;
videoPlayBackElement.Source = new Uri(videoUrl, UriKind.RelativeOrAbsolute);
if (tapSkipsVideo)
{
videoPlayBackElement.Tap += delegate { drawingSurfaceBackgroundElement.Children.Remove(videoPlayBackElement); };
}
drawingSurfaceBackgroundElement.Children.Add(videoPlayBackElement);
videoPlayBackElement.Play();
#endif
}
示例14: TestDetached
public void TestDetached ()
{
int media_opened_counter = 0;
int media_ended_counter = 0;
int media_failed_counter = 0;
int media_buffering_progress_counter = 0;
int media_download_progress_counter = 0;
int media_state_changed_counter = 0;
MediaElement mel = new MediaElement ();
TestPanel.Children.Add (mel);
mel.BufferingProgressChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
{
Debug.WriteLine ("BufferingProgressChanged");
media_buffering_progress_counter++;
});
mel.CurrentStateChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
{
Debug.WriteLine ("CurrentStateChanged");
media_state_changed_counter++;
});
mel.DownloadProgressChanged += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
{
Debug.WriteLine ("DownloadProgressChanged");
media_download_progress_counter++;
});
mel.MediaEnded += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
{
Debug.WriteLine ("MediaEnded");
media_ended_counter++;
});
mel.MediaFailed += new EventHandler<ExceptionRoutedEventArgs> (delegate (object sender, ExceptionRoutedEventArgs e)
{
Debug.WriteLine ("MediaFailed");
media_failed_counter++;
});
mel.MediaOpened += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
{
Debug.WriteLine ("MediaOpened");
media_opened_counter++;
});
mel.Source = new Uri ("/moon-unit;component/timecode-long-with-audio.wmv", UriKind.Relative);
// set all properties to non-defaults, to check which ones are reset
mel.AutoPlay = false;
mel.Balance = 0.7;
mel.BufferingTime = TimeSpan.FromSeconds (3.0);
mel.IsMuted = true;
mel.Volume = 0.33;
// wait until media has been opened
EnqueueConditional (() => media_opened_counter >= 1);
// check initial values
Enqueue (delegate ()
{
Assert.AreEqual (0.0, mel.Position.TotalMilliseconds, "Initial - Position");
});
// play
Enqueue (delegate ()
{
mel.Play ();
});
// wait until the media element is playing and has played 1 second
EnqueueConditional (() => mel.Position.TotalMilliseconds > 1.0);
// assert attached values
Enqueue (delegate ()
{
Assert.AreEqual (1, media_opened_counter, "Attached - MediaOpenedEvent");
Assert.AreEqual (0, media_ended_counter, "Attached - MediaEndedEvent");
Assert.AreEqual (0, media_failed_counter, "Attached - MediaFailedEvent");
Assert.IsGreater (0, media_buffering_progress_counter, "Attached - BufferingProgressChangedEvent");
Assert.IsGreater (0, media_download_progress_counter, "Attached - DownloadProgressChangedEvent");
Assert.IsGreater (0, media_state_changed_counter, "Attached - CurrentStateChangedEvent");
Assert.AreEqual (false, mel.AutoPlay, "Attached - AutoPlay");
Assert.AreEqualWithDelta (0.7, mel.Balance, 0.0001, "Attached - Balance");
Assert.AreEqual (1.0, mel.BufferingProgress, "Attached - BufferingProgress");
Assert.AreEqual (3.0, mel.BufferingTime.TotalSeconds, "Attached - BufferingTime");
Assert.AreEqual (true, mel.CanPause, "Attached - CanPause");
Assert.AreEqual (true, mel.CanSeek, "Attached - CanSeek");
Assert.AreEqual (MediaElementState.Playing, mel.CurrentState, "Attached - CurrentState");
Assert.AreEqual (true, mel.IsMuted, "Attached - IsMuted");
Assert.AreEqual (30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Attached - NaturalDuration");
Assert.IsGreater (1.0, mel.Position.TotalMilliseconds, "Attached - Position");
Assert.AreEqualWithDelta (0.33, mel.Volume, 0.0001, "Attached - Volume");
});
// detach
Enqueue (delegate ()
{
media_opened_counter = 0;
media_ended_counter = 0;
media_failed_counter = 0;
media_buffering_progress_counter = 0;
media_download_progress_counter = 0;
media_state_changed_counter = 0;
//.........这里部分代码省略.........
示例15: zoomVideo
/// <summary>
/// Zoom video, création de la progress bar, du "bouton" stop, des étoiles pleines et vides.
/// </summary>
/// <param name="sender">Video</param>
/// <param name="e">Evenement</param>
private void zoomVideo(object sender, MouseButtonEventArgs e)
{
if ((savingVideo == false)&&(clickLimit==false))
{
zoom = true;
maintenance.stopAllVideos();
fade = new Canvas();
fade.Background = Brushes.Black;
Grid.SetRowSpan(fade, 4);
Grid.SetColumnSpan(fade, 4);
fade.Opacity = 0.50;
gridMain.Children.Add(fade);
TimeSpan videoSize;
canvasHit = sender as Canvas;
String[] nameNumber = canvasHit.Name.Split('c', '_');
MediaElement video = videoRetriever(nameNumber[1], nameNumber[2]);
int videoNumber = ((Convert.ToInt32(nameNumber[1])) * 4) + (Convert.ToInt32(nameNumber[2]));
Uri uriZoom = video.Source;
zoomedVideo = new MediaElement();
Grid.SetRowSpan(zoomedVideo, 2);
Grid.SetColumnSpan(zoomedVideo, 2);
Grid.SetRow(zoomedVideo, 1);
Grid.SetColumn(zoomedVideo, 1);
zoomedVideo.Stretch = Stretch.Fill;
zoomedVideo.UnloadedBehavior = MediaState.Manual;
zoomedVideo.LoadedBehavior = MediaState.Manual;
zoomedVideo.MediaEnded += mediaEnded;
zoomedVideo.Source = uriZoom;
buttonStop = new Grid();
Canvas canvasStop = new Canvas();
canvasStop.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/cross.png")));
canvasStop.MouseLeftButtonDown += zoomedVideoStop_Click;
buttonStop.Children.Add(canvasStop);
buttonStop.Height = 100;
buttonStop.Width = 100;
buttonStop.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
buttonStop.VerticalAlignment = VerticalAlignment.Top;
progressBar = new System.Windows.Controls.ProgressBar();
progressBar.Margin = new Thickness(0, 0, 0, 194);
progressBar.Height = 30;
progressBar.Background = Brushes.PaleTurquoise;
progressBar.Foreground = Brushes.Blue;
Grid.SetColumnSpan(progressBar, 2);
Grid.SetColumn(progressBar, 1);
Grid.SetRow(progressBar, 3);
Grid.SetColumn(buttonStop, 2);
Grid.SetRow(buttonStop, 1);
favorites = new Grid();
favorites.Width = 100;
favorites.VerticalAlignment = VerticalAlignment.Top;
favorites.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
Grid.SetColumn(favorites, 1);
Grid.SetRow(favorites, 1);
Grid.SetRowSpan(favorites, 2);
for(int i=0;i<maintenance.getFavorite(videoNumber);i++)
{
if (i < 3)
{
RowDefinition line = new RowDefinition();
line.Height = new GridLength(100);
favorites.RowDefinitions.Add(line);
Canvas canvas = new Canvas();
canvas.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/starfull.png")));
Grid.SetRow(canvas, i);
favorites.Children.Add(canvas);
}
}
if (maintenance.getFavorite(videoNumber)<3)
{
if (hasVoted == false)
{
RowDefinition line = new RowDefinition();
line.Height = new GridLength(100);
favorites.RowDefinitions.Add(line);
canvasFavorite = new Canvas();
canvasFavorite.Background = new ImageBrush(new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Images/starempty.png")));
Grid.SetRow(canvasFavorite, maintenance.getFavorite(videoNumber));
favorites.Children.Add(canvasFavorite);
}
}
videoSize = TimeSpan.FromSeconds(15);
gridMain.Children.Add(zoomedVideo);
gridMain.Children.Add(buttonStop);
gridMain.Children.Add(progressBar);
gridMain.Children.Add(favorites);
progressBar.Minimum = 0;
progressBar.Maximum = videoSize.TotalSeconds;
timer.Interval = TimeSpan.FromMilliseconds(20);
timer.Tick += new EventHandler(progressTick);
timer.Start();
zoomedVideo.Position = TimeSpan.FromSeconds(15);
zoomedVideo.Play();
Console.WriteLine("Lecture de la vidéo zoomée : " + zoomedVideo.Source.ToString());
}
}