日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成...

發(fā)布時(shí)間:2025/3/15 windows 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
原文:與眾不同 windows phone (14) - Media(媒體)之音頻播放器, 視頻播放器, 與 Windows Phone 的音樂(lè)和視頻中心集成

[索引頁(yè)]
[源碼下載]


與眾不同 windows phone (14) - Media(媒體)之音頻播放器, 視頻播放器, 與 Windows Phone 的音樂(lè)和視頻中心集成



作者:webabcd


介紹
與眾不同 windows phone 7.5 (sdk 7.1) 之媒體

  • 音頻播放器
  • 視頻播放器
  • 與 Windows Phone 的音樂(lè)和視頻中心集成



示例
1、演示音頻播放器
Audio.xaml

<phone:PhoneApplicationPage x:Class="Demo.Media.Audio"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"FontFamily="{StaticResource PhoneFontFamilyNormal}"FontSize="{StaticResource PhoneFontSizeNormal}"Foreground="{StaticResource PhoneForegroundBrush}"SupportedOrientations="Portrait" Orientation="Portrait"mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"shell:SystemTray.IsVisible="True"><Grid x:Name="LayoutRoot" Background="Transparent"><StackPanel Orientation="Vertical"><MediaElement x:Name="mediaElement" Source="Assets/SuperMario.mp3" AutoPlay="False" /><Button x:Name="btnPlay" Content="播放" Click="btnPlay_Click" /><Button x:Name="btnPause" Content="暫停" Click="btnPause_Click" /><TextBlock x:Name="lblStatus" /></StackPanel></Grid></phone:PhoneApplicationPage>

Audio.xaml.cs

/** MediaElement - 用于播放視頻或音頻,本地地址或遠(yuǎn)程地址均可* 支持的編碼格式參見(jiàn):http://msdn.microsoft.com/en-us/library/ff462087(v=vs.92)* * MediaElement 的詳細(xì)說(shuō)明參見(jiàn):http://www.cnblogs.com/webabcd/archive/2008/12/01/1344632.html* Launcher 方式參見(jiàn):http://www.cnblogs.com/webabcd/archive/2012/06/14/2548776.html 中的 MediaPlayerLauncher* * XNA 播放音頻參見(jiàn):http://www.cnblogs.com/webabcd/archive/2011/07/11/2102713.html*/using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;namespace Demo.Media {public partial class Audio : PhoneApplicationPage{public Audio(){InitializeComponent();mediaElement.CurrentStateChanged += new RoutedEventHandler(mediaElement_CurrentStateChanged);}void mediaElement_CurrentStateChanged(object sender, RoutedEventArgs e){// 顯示 MediaElement 的當(dāng)前狀態(tài)lblStatus.Text = mediaElement.CurrentState.ToString();}private void btnPlay_Click(object sender, RoutedEventArgs e){// 播放 mediaElement.Play();}private void btnPause_Click(object sender, RoutedEventArgs e){// 暫停 mediaElement.Pause();}} }


2、演示視頻播放器
Video.xaml

<phone:PhoneApplicationPage x:Class="Demo.Media.Video"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"FontFamily="{StaticResource PhoneFontFamilyNormal}"FontSize="{StaticResource PhoneFontSizeNormal}"Foreground="{StaticResource PhoneForegroundBrush}"SupportedOrientations="Portrait" Orientation="Portrait"mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"shell:SystemTray.IsVisible="True"><Grid x:Name="LayoutRoot" Background="Transparent"><StackPanel Orientation="Vertical"><MediaElement x:Name="mediaElement" Source="Assets/Demo.mp4" AutoPlay="False" /><Button x:Name="btnPlay" Content="播放" Click="btnPlay_Click" /><Button x:Name="btnPause" Content="暫停" Click="btnPause_Click" /><TextBlock x:Name="lblStatus" /></StackPanel></Grid></phone:PhoneApplicationPage>

Video.xaml.cs

/** MediaElement - 用于播放視頻或音頻,本地地址或遠(yuǎn)程地址均可* 支持的編碼格式參見(jiàn):http://msdn.microsoft.com/en-us/library/ff462087(v=vs.92)* * MediaElement 的詳細(xì)說(shuō)明參見(jiàn):http://www.cnblogs.com/webabcd/archive/2008/12/01/1344632.html* Launcher 方式參見(jiàn):http://www.cnblogs.com/webabcd/archive/2012/06/14/2548776.html 中的 MediaPlayerLauncher*/using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;namespace Demo.Media {public partial class Video : PhoneApplicationPage{public Video(){InitializeComponent(); mediaElement.CurrentStateChanged += new RoutedEventHandler(mediaElement_CurrentStateChanged);}void mediaElement_CurrentStateChanged(object sender, RoutedEventArgs e){// 顯示 MediaElement 的當(dāng)前狀態(tài)lblStatus.Text = mediaElement.CurrentState.ToString();}private void btnPlay_Click(object sender, RoutedEventArgs e){// 播放 mediaElement.Play();}private void btnPause_Click(object sender, RoutedEventArgs e){// 暫停 mediaElement.Pause();}} }


3、演示如何與 Windows Phone 的音樂(lè)和視頻中心集成
IntegrateWithTheMusicAndVideoHub.xaml

<phone:PhoneApplicationPage x:Class="Demo.Media.IntegrateWithTheMusicAndVideoHub"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"FontFamily="{StaticResource PhoneFontFamilyNormal}"FontSize="{StaticResource PhoneFontSizeNormal}"Foreground="{StaticResource PhoneForegroundBrush}"SupportedOrientations="Portrait" Orientation="Portrait"mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"shell:SystemTray.IsVisible="True"><Grid x:Name="LayoutRoot" Background="Transparent"><StackPanel Orientation="Vertical"><TextBlock TextWrapping="Wrap"><Run>本 app 會(huì)出現(xiàn)在“音樂(lè)視頻中心”中的“應(yīng)用程序”下</Run><LineBreak /><Run>操作完成后,請(qǐng)去“音樂(lè)視頻中心”看效果</Run></TextBlock><Button x:Name="btnNow" Content="設(shè)置“音樂(lè)視頻中心”中的“正在播放磁貼”" Click="btnNow_Click" /><Button x:Name="btnRecent" Content="向“音樂(lè)視頻中心”中的“歷史記錄”添加新的磁貼" Click="btnRecent_Click" /><Button x:Name="btnAcquired" Content="向“音樂(lè)視頻中心”中的“最新上市”添加新的磁貼" Click="btnAcquired_Click" /></StackPanel></Grid></phone:PhoneApplicationPage>

IntegrateWithTheMusicAndVideoHub.xaml.cs

/** 本例演示如何將 app 集成進(jìn)“音樂(lè)視頻中心”* * MediaHistoryItem - 出現(xiàn)在“音樂(lè)視頻中心”中的磁貼對(duì)象(包括“正在播放”,“歷史記錄”和“最新上市”)* ImageStream - 磁貼上需要顯示的背景圖片流* Title - 磁貼的標(biāo)題* PlayerContext - key/value 對(duì)集合,用戶點(diǎn)擊“歷史記錄”或“最新上市”中的某個(gè)磁貼會(huì)進(jìn)入到 app 的主頁(yè)面,同時(shí)也會(huì)將對(duì)應(yīng)的 key/value 數(shù)據(jù)一同帶過(guò)去,參見(jiàn) MainPage.xaml.cs* * MediaHistory - 管理 MediaHistoryItem 的類* Instance - 獲得 MediaHistory 實(shí)例* NowPlaying - 指定“正在播放”對(duì)象,MediaHistoryItem 類型* WriteRecentPlay(MediaHistoryItem item) - 在“歷史記錄”中增加一個(gè)指定的 MediaHistoryItem 對(duì)象* WriteAcquiredItem(MediaHistoryItem item) - 在“最新上市”中增加一個(gè)指定的 MediaHistoryItem 對(duì)象* * * 注意:* 1、“正在播放”磁貼大小為 358 * 358,背景圖不能大于 75 KB* 2、“歷史記錄”和“最新上市”磁貼大小為 173 * 173* 3、app 提交到商店審核時(shí),如果認(rèn)證程序檢測(cè)到 app 調(diào)用了 MediaHistory 和 MediaHistoryItem,則此 app 就會(huì)出現(xiàn)在“音樂(lè)視頻中心”的應(yīng)用程序中* 4、出于測(cè)試目的,如果想在 app 提交商店前使其出現(xiàn)在“音樂(lè)視頻中心”的應(yīng)用程序中的話,需要修改 manifest,在 <App /> 中增加 HubType="1"* 5、MediaHistoryItem 的 PlayerContext 指定的 key/value 對(duì)集合是 MediaHistoryItem 的上下文數(shù)據(jù),用戶在“歷史記錄”或“最新上市”單擊某個(gè)磁貼對(duì)象時(shí),會(huì)跳轉(zhuǎn)到 app 的主頁(yè)面,同時(shí)將對(duì)應(yīng)的 key/value 數(shù)據(jù)一同帶過(guò)去,其可以在主頁(yè)面通過(guò) NavigationContext.QueryString[key] 獲取到,參見(jiàn) MainPage.xaml.cs*/using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls;using Microsoft.Devices; using System.IO; using System.Windows.Resources; using System.IO.IsolatedStorage; using Microsoft.Phone.BackgroundAudio;namespace Demo.Media {public partial class IntegrateWithTheMusicAndVideoHub : PhoneApplicationPage{public IntegrateWithTheMusicAndVideoHub(){InitializeComponent();PlayAudio();}// 播放一個(gè)音頻private void PlayAudio(){// 由于播放本地音頻時(shí)只能從獨(dú)立存儲(chǔ)中播放,所以此處把示例用音頻文件從程序包中復(fù)制到獨(dú)立存儲(chǔ)using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()){if (!storage.FileExists("SuperMario.mp3")){StreamResourceInfo resource = Application.GetResourceStream(new Uri("Assets/SuperMario.mp3", UriKind.Relative));using (IsolatedStorageFileStream file = storage.CreateFile("SuperMario.mp3")){int chunkSize = 4096;byte[] bytes = new byte[chunkSize];int byteCount;while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0){file.Write(bytes, 0, byteCount);}}}}BackgroundAudioPlayer.Instance.Play();}private void btnNow_Click(object sender, RoutedEventArgs e){StreamResourceInfo sri = Application.GetResourceStream(new Uri("Assets/TileBackgroundRed.png", UriKind.Relative));MediaHistoryItem mediaHistoryItem = new MediaHistoryItem();mediaHistoryItem.ImageStream = sri.Stream;mediaHistoryItem.Title = "正在播放";mediaHistoryItem.PlayerContext.Add("keyNow", "正在播放的音樂(lè)");MediaHistory.Instance.NowPlaying = mediaHistoryItem;}private void btnRecent_Click(object sender, RoutedEventArgs e){StreamResourceInfo sri = Application.GetResourceStream(new Uri("Assets/TileBackgroundGreen.png", UriKind.Relative));MediaHistoryItem mediaHistoryItem = new MediaHistoryItem();mediaHistoryItem.ImageStream = sri.Stream;mediaHistoryItem.Title = "最近播放";mediaHistoryItem.PlayerContext.Add("keyRecent", "最近播放的音樂(lè)");MediaHistory.Instance.WriteRecentPlay(mediaHistoryItem);}private void btnAcquired_Click(object sender, RoutedEventArgs e){StreamResourceInfo sri = Application.GetResourceStream(new Uri("Assets/TileBackgroundBlue.png", UriKind.Relative));MediaHistoryItem mediaHistoryItem = new MediaHistoryItem();mediaHistoryItem.ImageStream = sri.Stream;mediaHistoryItem.Title = "最新上市";mediaHistoryItem.PlayerContext.Add("keyAcquired", "最新上市的音樂(lè)");MediaHistory.Instance.WriteAcquiredItem(mediaHistoryItem);}} }



OK
[源碼下載]

總結(jié)

以上是生活随笔為你收集整理的与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。