本文整理汇总了C#中Windows.UI.Xaml.Controls.MediaElement类的典型用法代码示例。如果您正苦于以下问题:C# MediaElement类的具体用法?C# MediaElement怎么用?C# MediaElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaElement类属于Windows.UI.Xaml.Controls命名空间,在下文中一共展示了MediaElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainPage
public MainPage()
{
this.DataContext = App.s_bike;
this.InitializeComponent();
_speech = new SpeechSynthesizer();
_audio = new MediaElement();
_audio.Volume = 1;
App.s_bike.iFitLED = C7ZL.OnOff.On;
App.s_bike.HeartRateChanged += m_bike_HeartRateChanged;
App.s_bike.RpmChanged += m_bike_RpmChanged;
App.s_bike.DifficultyChanged += m_bike_DifficultyChanged;
App.s_bike.ButtonDownPressed += S_bike_ButtonDownPressed;
App.s_bike.ButtonUpPressed += S_bike_ButtonUpPressed;
App.s_bike.ButtonEnterPressed += S_bike_ButtonEnterPressed;
App.s_bike.DialClickedClockwise += m_bike_DialClickedClockwise;
App.s_bike.DialClickedAnticlockwise += m_bike_DialClickedAnticlockwise;
tbDifficulty_value.Text = App.s_bike.Difficulty.ToString();
}
示例2: ProactiveViewModel
/// <summary>
/// A view model class for the IndivReactive Scenario.
/// </summary>
public ProactiveViewModel(MediaElement mediaElement)
{
/// The ProtectionManager provides communication between the player and PlayReady DRM.
/// The helper class will configure the protection manager for PlayReady and assign an
/// event handler for Service requests.
this.ProtectionManager = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
mediaElement.ProtectionManager = this.ProtectionManager;
/// The PlayReadyInfoViewModel is used in this sample app to show PlayReadyStatistics such as
/// SecurityLevel and hardware support within the UI.
PlayReadyInfo = new PlayReadyInfoViewModel();
PlayReadyInfo.RefreshStatics();
mediaElement.CurrentStateChanged += (s, a) => {
ViewModelBase.Log("Media State::" + mediaElement.CurrentState);
};
mediaElement.MediaFailed += (s, a) => {
ViewModelBase.Log("Media Failed::" + a.ErrorMessage);
};
/// Proactive license acqusition will ensure a license is available
/// prior to playback
CmdGetLicense = new RelayCommand(() => { GetLicense(new Guid(this.KeyId)); }, () => { return PlayReadyHelpers.IsIndividualized; });
/// Play is enabled once a license is available
CmdPlayMovie = new RelayCommand(() => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); },
() => IsLicenseAvailable(new Guid(KeyId)));
CmdStopMovie = new RelayCommand(() => { mediaElement.Stop(); SetPlaybackEnabled(false); },
() => IsLicenseAvailable(new Guid(KeyId)));
/// Proactive individualization will ensure PlayReady have been configured
/// to begin making license requests
IndividualizeIfNeeded();
}
示例3: OnElementChanged
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Frame> e)
{
base.OnElementChanged(e);
if (Element == null)
return;
player = new MediaElement();
player.AutoPlay = true;
player.MediaOpened += (sender, args) =>
{
timer.Start();
};
this.Control.Child = player;
timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 1) };
timer.Tick += timer_Tick;
if (string.IsNullOrWhiteSpace(Player.Url))
return;
InitPlayer();
}
示例4: InitializeComponent
public void InitializeComponent()
{
if (_contentLoaded)
return;
_contentLoaded = true;
Application.LoadComponent(this, new System.Uri("ms-appx:///Tweet.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);
pageRoot = (Mu_genotype1.Common.LayoutAwarePage)this.FindName("pageRoot");
primaryColumn = (Windows.UI.Xaml.Controls.ColumnDefinition)this.FindName("primaryColumn");
progbar = (Windows.UI.Xaml.Controls.ProgressBar)this.FindName("progbar");
titlePanel = (Windows.UI.Xaml.Controls.Grid)this.FindName("titlePanel");
itemListScrollViewer = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemListScrollViewer");
itemListScrollViewer2 = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemListScrollViewer2");
PeerTweets = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("PeerTweets");
itemListView2 = (Windows.UI.Xaml.Controls.ListView)this.FindName("itemListView2");
mediaPlayer = (Windows.UI.Xaml.Controls.MediaElement)this.FindName("mediaPlayer");
TweetBox = (Windows.UI.Xaml.Controls.TextBox)this.FindName("TweetBox");
TweetIt = (Windows.UI.Xaml.Controls.Button)this.FindName("TweetIt");
PinPanel = (Windows.UI.Xaml.Controls.StackPanel)this.FindName("PinPanel");
itemListView = (Windows.UI.Xaml.Controls.ListView)this.FindName("itemListView");
PinTb = (Windows.UI.Xaml.Controls.TextBox)this.FindName("PinTb");
VerifyPinButton = (Windows.UI.Xaml.Controls.Button)this.FindName("VerifyPinButton");
backButton = (Windows.UI.Xaml.Controls.Button)this.FindName("backButton");
pageTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("pageTitle");
pageSubtitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("pageSubtitle");
FullScreenLandscape = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenLandscape");
Filled = (Windows.UI.Xaml.VisualState)this.FindName("Filled");
FullScreenPortrait = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait");
FullScreenPortrait_Detail = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait_Detail");
Snapped = (Windows.UI.Xaml.VisualState)this.FindName("Snapped");
Snapped_Detail = (Windows.UI.Xaml.VisualState)this.FindName("Snapped_Detail");
TwitterConnectBtn = (Windows.UI.Xaml.Controls.Button)this.FindName("TwitterConnectBtn");
RefreshButton = (Windows.UI.Xaml.Controls.Button)this.FindName("RefreshButton");
}
示例5: Speaker
/// <summary>
/// have MediaElement defined in your XAML and pass it here
/// </summary>
/// <param name="_media"></param>
public Speaker(MediaElement _media)
{
media = _media;
media.MediaEnded += MediaElement_SpeakEnded;
synthesizer = new SpeechSynthesizer();
}
示例6: StartMediaElement
private async void StartMediaElement()
{
// To use AudioCategory.BackgroundCapableMedia:
// * OnWindows 8 set MediaControl.PlayPressed, MediaControl.PausePressed,
// MediaControl.PlayPauseTogglePressed and MediaControl.StopPressed.
// * On Windows 8.1 set SystemMediaTransportControls.ButtonPressed.
systemControls = SystemMediaTransportControls.GetForCurrentView();
systemControls.ButtonPressed += OnButtonPressed;
systemControls.IsPlayEnabled = true;
systemControls.IsPauseEnabled = true;
systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;
mediaPlayer = new MediaElement();
mediaPlayer.AudioCategory = AudioCategory.BackgroundCapableMedia;
mediaPlayer.AutoPlay = true;
mediaPlayer.CurrentStateChanged += OnCurrentStateChanged;
this.Content = mediaPlayer;
HttpClient client = new HttpClient();
// Add custom headers or credentials.
client.DefaultRequestHeaders.Add("Foo", "Bar");
//Uri uri = new Uri("http://localhost/song.mp3?slow=1000&?bufferlength=100000&lastModified=true");
Uri uri = new Uri("http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4");
HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);
// If you need to use HttpClient, use MediaElement.SetSource() instead of MediaElement.Source.
mediaPlayer.SetSource(stream, stream.ContentType);
}
示例7: Play
public async Task Play(Song a, MediaElement m)
{
if (Songs.Count != 0)
{
if (Songs.Contains(a))
{
NowIndex = Songs.IndexOf(a);
}
else
{
Songs.Add(a);
NowIndex = Songs.IndexOf(a);
}
}
else
{
Songs.Add(a);
NowIndex = 0;
}
await Task.Run(() =>
{
a.PlayOnce();
});
var stream = await a.AudioFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
m.SetSource(stream, a.AudioFile.ContentType);
OnNotifyPlayBackEvent(a);
}
示例8: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
{
MakePinWebAPICall();
try
{
//Create a new object for the color sensor class
colorSensor = new TCS34725();
//Initialize the sensor
await colorSensor.Initialize();
//Create a new SpeechSynthesizer
synthesizer = new SpeechSynthesizer();
//Create a new MediaElement
audio = new MediaElement();
//Initialize the GPIO pin for the pushbutton
InitializeGpio();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
示例9: MediaElementOut
public MediaElementOut(MediaElement mediaElement)
{
this.mediaElement = mediaElement;
mediaElement.MediaFailed += mediaElement_MediaFailed;
mediaElement.MediaOpened += MediaElementOnMediaOpened;
mediaElement.CurrentStateChanged += MediaElementOnCurrentStateChanged;
}
示例10: MainPage
public MainPage()
{
this.InitializeComponent();
if (!CheckForInternetAccess())
{
string msg1 = "An Internet connection is required for this app and it appears that you are not connected." + Environment.NewLine + Environment.NewLine;
string msg2 = "Make sure that you have an active Internet connection and try again.";
UpdateStatus("You are not connected to the Internet", true);
new MessageDialog(msg1 + msg2, "No Internet").ShowAsync();
}
else
{
InitNotificationsAsync();
}
mediaplayer = new MediaElement();
// On Windows, the Send button must be made visible since the Command Bar is not always
// visible and we don't want to force the user to swipe up every time they want to chat.
#if WINDOWS_APP
btnWinSend.Visibility = Windows.UI.Xaml.Visibility.Visible;
TextInput.Height = btnWinSend.Height;
#endif
}
示例11: NowPlayingPageViewModel
public NowPlayingPageViewModel()
{
App.Current.Suspending += Current_Suspending;
App.Current.Resuming += Current_Resuming;
SongHistory = new ObservableCollection<ShoutcastSongHistoryItem>();
mediaElement = ((App)App.Current).MediaElement;
PlayCommand = CommandManager.CreateCommand(() =>
{
if (mediaElement != null)
if (mediaElement.CurrentState != MediaElementState.Playing)
{
mediaElement.Play();
MediaControl.IsPlaying = true;
}
});
PauseCommand = CommandManager.CreateCommand(() =>
{
if (mediaElement != null)
if (mediaElement.CurrentState != MediaElementState.Paused)
{
mediaElement.Pause();
MediaControl.IsPlaying = false;
}
});
}
示例12: Initialize
/// <summary>
/// Initialize VideoPlayer.
/// </summary>
private static void Initialize(VideoStretch stretch)
{
#if NETFX_CORE
if (_videoPopup == null)
{
_videoPopup = new Popup();
}
_videoPopup.VerticalOffset = 0;
_videoPopup.HorizontalOffset = 0;
if (_videoElement == null)
{
_videoElement = new MediaElement();
}
_videoPopup.Child = _videoElement;
_videoElement.MediaEnded += _videoElement_MediaEnded;
_videoElement.MediaOpened += _videoElement_MediaOpened;
_videoPopup.Height = Window.Current.Bounds.Height;
_videoPopup.Width = Window.Current.Bounds.Width;
_videoElement.Tapped += _videoElement_Tapped;
_videoElement.Stretch = (Stretch)stretch;
_videoElement.AutoPlay = false;
_videoElement.Height = _videoPopup.Height;
_videoElement.Width = _videoPopup.Width;
_videoPopup.IsOpen = true;
#endif
}
示例13: StartTextToSpeech
static public async Task StartTextToSpeech(string text)
{
if (!string.IsNullOrEmpty(text))
{
try
{
if (_speech != null)
{
StopTextToSpeech();
}
var voice = GetSpeechVoice();
if (voice != null)
{
_speech = new SpeechSynthesizer();
_speech.Voice = voice;
SpeechSynthesisStream speechStream = await _speech.SynthesizeTextToStreamAsync(Utility.DecodeHtml(text));
_soundPlayer = new MediaElement();
_soundPlayer.SetSource(speechStream, speechStream.ContentType);
_soundPlayer.Play();
}
}
catch (Exception ex)
{
AppLogs.WriteError("SpeechServices", ex);
}
}
}
示例14: ReactiveViewModel
/// <summary>
/// A view model class for the ReactiveRequest Scenario.
/// The ViewModel takes a UI MediaElement in the contructor to wire up commands and events to simplify the sample.
/// Decoupling the MediaElement from the ViewModel would require addtional MVVM infrastucture.
/// </summary>
public ReactiveViewModel(MediaElement mediaElement)
{
/// The ProtectionManager provides communication between the player and PlayReady DRM.
/// The helper class will configure the protection manager for PlayReady and assign an
/// event handler for Service requests.
this.ProtectionManager = PlayReadyHelpers.InitializeProtectionManager(ServiceRequested);
mediaElement.ProtectionManager = this.ProtectionManager;
/// The PlayReadyInfoViewModel is used in this sample app to show PlayReadyStatistics such as
/// SecurityLevel and hardware support in the UI.
PlayReadyInfo = new PlayReadyInfoViewModel();
PlayReadyInfo.RefreshStatics();
/// Reactive license acqusition will happen automatically when setting the source of
/// a MediaElement to protected content.
CmdPlayMovie = new RelayCommand( () => { mediaElement.Source = new Uri(moviePath); SetPlaybackEnabled(true); });
/// The licenseUrl in the sample is set to return a non-peristent license. When there is a
/// hard Stop() on the playback, a new license will be requested on Play().
CmdStopMovie = new RelayCommand(() => { mediaElement.Stop(); SetPlaybackEnabled(false); });
mediaElement.CurrentStateChanged += (s, a) => {
ViewModelBase.Log("Media State::" + mediaElement.CurrentState);
};
mediaElement.MediaFailed += (s, a) => {
ViewModelBase.Log("Err::" + a.ErrorMessage);
};
}
示例15: GameViewModel
protected GameViewModel()
: base()
{
CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
MediaPlayer = new MediaElement();
});
lock (locker)
{
if (StopwatchFile == null || AlarmFile == null)
{
LoadFileTask = Task.Run(async () =>
{
StorageFolder folder = await (await Package.Current.InstalledLocation.GetFolderAsync("Assets")).GetFolderAsync("Sounds");
StopwatchFile = await folder.GetFileAsync("Stopwatch.wav");
AlarmFile = await folder.GetFileAsync("Alarm.wav");
CheerFile = await folder.GetFileAsync("Cheer.wav");
AwwFile = await folder.GetFileAsync("Aww.wav");
VictoryFile = await folder.GetFileAsync("Victory.wav");
(await StopwatchFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(StopwatchStream);
(await AlarmFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(AlarmStream);
(await CheerFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(CheerStream);
(await AwwFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(AwwStream);
(await VictoryFile.OpenAsync(FileAccessMode.Read)).AsStream().CopyTo(VictoryStream);
});
}
}
}