我有一個.wav音樂文件。 當我試圖播放使用SoundEffect.Play();玩聲音窗口時發出噪音手機7模擬器
mus1.Play();我得到的是噪音而不是音樂。 在PC音樂播放器中播放效果也很好。 如何解決此問題?
如何確保它能在Windows Phone 7中發揮出色呢?
我有一個.wav音樂文件。 當我試圖播放使用SoundEffect.Play();玩聲音窗口時發出噪音手機7模擬器
mus1.Play();我得到的是噪音而不是音樂。 在PC音樂播放器中播放效果也很好。 如何解決此問題?
如何確保它能在Windows Phone 7中發揮出色呢?
這聽起來像WP7不理解.wav文件中的內容。爲什麼不嘗試將它轉換爲.wav(是的,我知道它已經在.wav中),因爲這可能會刪除未知數據。
Audacity(http://audacity.sourceforge.net/)是免費的,將爲您做到這一點。只需將.wav文件拖入其中,然後單擊文件 - >導出...
我很抱歉重新點燃一箇舊帖子,但我得到的是同樣的東西,但只是改變爲.WAV與Audacity不能解決它對我來說,你能幫忙嗎? http://stackoverflow.com/questions/13157992/audio-distored-and-incomprehensible-using-windows-phone-mediaelement(我在實際設備上獲得了失真而不是聲音音頻) – GONeale 2012-11-01 13:43:08
試試下面的代碼
MainPage.xaml.cs中
namespace MediaSample
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
progress.DataContext = this;
this.Loaded += new System.Windows.RoutedEventHandler(MainPage_Loaded);
mediaplayer.BufferingProgressChanged += new System.Windows.RoutedEventHandler(mediaplayer_BufferingProgressChanged);
mediaplayer.CurrentStateChanged += new RoutedEventHandler(mediaplayer_CurrentStateChanged);
}
public double Duration { get; set; }
void mediaplayer_CurrentStateChanged(object sender, RoutedEventArgs e)
{
if (mediaplayer.CurrentState == MediaElementState.Playing)
{
Duration = mediaplayer.NaturalDuration.TimeSpan.TotalSeconds;
ThreadPool.QueueUserWorkItem(o =>
{
while (true)
{
Dispatcher.BeginInvoke(new Action(() => Progress = mediaplayer.Position.TotalSeconds * 100/Duration));
Thread.Sleep(0);
}
});
}
}
void mediaplayer_BufferingProgressChanged(object sender, System.Windows.RoutedEventArgs e)
{
MediaElement mediaplayer = sender as MediaElement;
if (mediaplayer.BufferingProgress == 1)
Debug.WriteLine(mediaplayer.NaturalDuration);
}
void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
mediaplayer.Source = new Uri("/Oru nalum..mp3", UriKind.Relative);
mediaplayer.Play();
}
public double Progress
{
get { return (double)GetValue(ProgressProperty); }
set { SetValue(ProgressProperty, value); }
}
// Using a DependencyProperty as the backing store for Progress. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ProgressProperty =
DependencyProperty.Register("Progress", typeof(double), typeof(PhoneApplicationPage), new PropertyMetadata(0.0));
}
}
MainPage.xaml中
<phone:PhoneApplicationPage
x:Class="MediaSample.MainPage"
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"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Media Application" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="mediaplayer"/>
<ProgressBar Height="40" x:Name="progress" Value="{Binding Path=Progress}"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
外接MP3文件,如下所示,
一樣,你可以添加.wav文件。運作良好。上面的測試代碼。 謝謝。
使用MeadiaElement而不是使用SoundEffect類。 試試這個 MediaElement
您可以發佈一些代碼讓我們知道您嘗試了什麼嗎? – abhinav 2012-02-16 12:31:51
法郎,這似乎是一個模擬器的問題......你不能讓某人測試你的應用程序,看看問題是什麼?如果你喜歡,你可以通過互聯網發佈一個示例XAP,我或其他開發者一定會幫助你測試並檢查問題是否存在於一個物理設備中。 – 2012-03-28 10:00:04