【问题标题】:Getting noise when playing sound windows phone 7 emulator播放声音 windows phone 7 模拟器时出现噪音
【发布时间】:2012-02-16 09:09:16
【问题描述】:

我有一个 .wav 音乐文件。 当我尝试使用 SoundEffect.Play() 播放时;

mus1.Play();我得到的是噪音而不是音乐。 在 PC 音乐播放器中也可以很好地播放。 如何解决这个问题?

如何确保它在 Windows Phone 7 中也能正常运行?

【问题讨论】:

  • 您能否发布一些代码让我们知道您尝试了什么?
  • Francly,这似乎是模拟器的问题......你不能找人测试你的应用程序看看问题是什么吗?如果您愿意,您可以在互联网上发布一个示例 XAP,我或其他开发人员一定会帮助您测试并检查问题是否在物理设备中仍然存在!

标签: windows-phone-7 audio


【解决方案1】:

听起来 .wav 文件中有 WP7 不理解的内容。为什么不尝试将其转换为 .wav(是的,我知道它已经在 .wav 中),因为这可能会删除未知数据。

Audacity (http://audacity.sourceforge.net/) 是免费的,会为您完成。只需将 .wav 文件拖入其中,然后单击文件 --> 导出...

【讨论】:

  • 我很抱歉重新点燃一个旧帖子,但我得到了同样的东西,但是简单地用 Audacity 更改为 .WAV 并不能为我解决这个问题,你能帮忙吗? stackoverflow.com/questions/13157992/…(在实际设备上我得到的是失真而不是人声)
【解决方案2】:

试试下面的代码

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 文件。工作很好。上面测试过的代码。 谢谢。

【讨论】:

    【解决方案3】:

    使用 MediaElement 而不是使用 SoundEffect 类。 试试这个 MediaElement

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 2015-02-11
      • 2023-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      相关资源
      最近更新 更多