Silverlight デベロッパー センター >
Silverlight フォーラム
>
Silverlight - ビデオとメディア
>
Visual Studio 2008でビルドするとMediaError
Visual Studio 2008でビルドするとMediaError
- 質問させていただきます。Blend2でプロジェクトを作成し以下のコードを記述した場合では正常にビルド後、ブラウザ表示され音も鳴りますが、Visual Studio 2008でプロジェクトを作成した場合に同様のコードを記述すると、正常にビルドはできますが、プラグインエラーが表示され、音も鳴りません。■Visual Studio 2008からプロジェクトを作成した場合-------------------------------------------------------<UserControl x:Class="soudTestVS2008.Page"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Width="400" Height="300"><Grid x:Name="LayoutRoot" Background="White"><MediaElement x:Name="sound" Source="sound.mp3" AutoPlay="False"/><Button Margin="232,176,224,168" Content="Button" x:Name="Btn"/></Grid></UserControl>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;namespace soudTestVS2008{public partial class Page : UserControl{public Page(){InitializeComponent();LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);}void LayoutRoot_Loaded(object sender, RoutedEventArgs e){Btn.Click += new RoutedEventHandler(Btn_Click);}void Btn_Click(object sender, RoutedEventArgs e){sound.Stop();sound.Play();}}}-------------------------------------------------------■Blend2からプロジェクトを作成した場合-------------------------------------------------------<UserControlxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"x:Class="soundTest.Page"Width="640" Height="480"><Grid x:Name="LayoutRoot" Background="White"><MediaElement x:Name="sound" Source="sound.mp3" AutoPlay="False"/><Button Margin="232,176,224,168" Content="Button" x:Name="Btn"/></Grid></UserControl>using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace soundTest{public partial class Page : UserControl{public Page(){InitializeComponent();LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);}void LayoutRoot_Loaded(object sender, RoutedEventArgs e){Btn.Click += new RoutedEventHandler(Btn_Click);}void Btn_Click(object sender, RoutedEventArgs e){sound.Stop();sound.Play();}}}-------------------------------------------------------以下の方法でも同様。-----------------------------------MediaElement sound = new MediaElement();sound.Source = new Uri("sound.mp3", UriKind.Relative);LayoutRoot.Children.Add(sound);-----------------------------------エラーコード:#4001ご教授宜しくお願いいたします。
- 編集済みmonkShape 2009年6月7日 7:48
回答
- 大西さまご返答いただきありがとうございます。おっしゃる通り、リンクパスが通ってない事が原因でした。VS2008から作る時、MediaElementのリンクパスはXMALでの埋め込みは止めてC#で絶対パス設定に変更します。修正版----------------------------------------<UserControl x:Class="soudTestVS2008.Page"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Width="400" Height="300"><Grid x:Name="LayoutRoot" Background="White"><MediaElement x:Name="sound" AutoPlay="False"/><Button Margin="232,176,224,168" Content="Button" x:Name="Btn"/></Grid></UserControl>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;namespace soudTestVS2008{public partial class Page : UserControl{public Page(){InitializeComponent();LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);}void LayoutRoot_Loaded(object sender, RoutedEventArgs e){Btn.Click += new RoutedEventHandler(Btn_Click);sound.Source = new Uri("http://localhost:XXXXX/sound.mp3", UriKind.Absolute);}void Btn_Click(object sender, RoutedEventArgs e){sound.Stop();sound.Play();}}}----------------------------------------ありがとうございました。
- 回答としてマークmonkShape 2009年6月11日 3:49
動作するようになってよかったですね。
1点だけ補足です。
sound.Stop();
sound.Play();
は、おそらく1度再生が終了したメディアに対しての対応かと思います。メディアの再生位置を先頭に戻すには、MediaElement.Positionプロパティも利用できます。
sound.Position = new TimeSpan(0);
sound.Play();
という書き方もできます。
この投稿は現状のまま何の保証もなく掲載しているものであり、何らかの権利を許諾するものでもありません。コミュニティにおけるマイクロソフト社員による発言やコメントは、マイクロソフトの正式な見解またはコメントではありません。詳しくは http://www.microsoft.com/japan/communities/msp.mspx をご覧ください。- 回答としてマークmonkShape 2009年6月11日 3:50
すべての返信
- エラーコード #4001 (AG_E_NETWORK_ERROR)ということは、メディアのURIが解決できていないことが考えられます。
Silverlight 2のアプリケーションをホストするためのWebサイトとHTMLをご覧いただき、.xapファイルと同じフォルダにsound.mp3があるかどうかご確認いただけませんか。おそらく、Blend 2側では同じフォルダに.xapとメディアファイルがあり、エラーが発生しているVisual Studio 2008側のプロジェクトファイルでは同じフォルダに存在しないと思います。
この投稿は現状のまま何の保証もなく掲載しているものであり、何らかの権利を許諾するものでもありません。コミュニティにおけるマイクロソフト社員による発言やコメントは、マイクロソフトの正式な見解またはコメントではありません。詳しくは http://www.microsoft.com/japan/communities/msp.mspx をご覧ください。 - 大西さまご返答いただきありがとうございます。おっしゃる通り、リンクパスが通ってない事が原因でした。VS2008から作る時、MediaElementのリンクパスはXMALでの埋め込みは止めてC#で絶対パス設定に変更します。修正版----------------------------------------<UserControl x:Class="soudTestVS2008.Page"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Width="400" Height="300"><Grid x:Name="LayoutRoot" Background="White"><MediaElement x:Name="sound" AutoPlay="False"/><Button Margin="232,176,224,168" Content="Button" x:Name="Btn"/></Grid></UserControl>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;namespace soudTestVS2008{public partial class Page : UserControl{public Page(){InitializeComponent();LayoutRoot.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);}void LayoutRoot_Loaded(object sender, RoutedEventArgs e){Btn.Click += new RoutedEventHandler(Btn_Click);sound.Source = new Uri("http://localhost:XXXXX/sound.mp3", UriKind.Absolute);}void Btn_Click(object sender, RoutedEventArgs e){sound.Stop();sound.Play();}}}----------------------------------------ありがとうございました。
- 回答としてマークmonkShape 2009年6月11日 3:49
動作するようになってよかったですね。
1点だけ補足です。
sound.Stop();
sound.Play();
は、おそらく1度再生が終了したメディアに対しての対応かと思います。メディアの再生位置を先頭に戻すには、MediaElement.Positionプロパティも利用できます。
sound.Position = new TimeSpan(0);
sound.Play();
という書き方もできます。
この投稿は現状のまま何の保証もなく掲載しているものであり、何らかの権利を許諾するものでもありません。コミュニティにおけるマイクロソフト社員による発言やコメントは、マイクロソフトの正式な見解またはコメントではありません。詳しくは http://www.microsoft.com/japan/communities/msp.mspx をご覧ください。- 回答としてマークmonkShape 2009年6月11日 3:50


