0

私は本当にこれで立ち往生しています。これまでのところ、MSDN フォーラムの誰も私を助けることができませんでした。

編集された AppStudio アプリである MVVM アプリがあります。アプリにポッドキャスト機能を追加しています。この機能は、ポッドキャストのオーディオがバックグラウンドで再生されないという事実を除けば、完全に機能します。

バックグラウンド対応メディアである MediaElement で宣言しました。これが私のビューのXAMLです

<DataTemplate x:Key="PodCast1DetailDetail">
    <ScrollViewer>
        <StackPanel>
            <TextBlock Margin="0,16" Text="{Binding Title, Converter={StaticResource TextPlainConverter}, ConverterParameter = 140}" Style="{StaticResource SubHeaderText}" />
            <MediaElement x:Name="PodCast" 
                Source="{Binding Enclosure}"
                PosterSource="{Binding PodcastImg}"
                CurrentStateChanged="Media_CurrentStateChanged"
                RateChanged="Media_RateChanged"
                AreTransportControlsEnabled ="True"
                AudioCategory="BackgroundCapableMedia"
                Stretch="UniformToFill"
                Width="340"
                Height="auto"
                MediaFailed="Media_MediaFailed"
                MediaOpened="Media_MediaOpened"
                MediaEnded="Media_MediaEnded"
                AutoPlay="False"
                HorizontalAlignment="Stretch"/>



                <!--<Image Source="{Binding ImageUrl, Converter={StaticResource ThumbnailConverter}, ConverterParameter=300}" Stretch="Uniform" />-->
            <TextBlock Margin="0,12" Style="{StaticResource ItemContentText}" Text="{Binding Content, Converter={StaticResource TextPlainConverter}}" />
            <!--<controls:WebControl Html="{Binding Content}" Width="auto" Height="1000" Foreground="{StaticResource AppForegroundColor}" />-->
        </StackPanel>
    </ScrollViewer>
</DataTemplate>

詳細ページの XAML は次のとおりです。

<FlipView x:Name="FlipViewPodCast" Grid.Row="1" TabIndex="1"
        DataContext="{Binding NextCastModel}"
          ItemsSource="{Binding Items}"
          ItemTemplate="{StaticResource NextCast1DetailDetail}"
          SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
          ItemContainerStyle="{StaticResource FlipItemStyle}">
     </FlipView>

詳細ページの背後にあるすべてのコードに従います。

    using System;
using System.Diagnostics;
using System.Threading;
using System.Net.NetworkInformation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.DataTransfer;
using Windows.Media;
using Windows.Media.Playback;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using AppStudio.Services;
using AppStudio.ViewModels;


namespace AppStudio.Views
{
    public sealed partial class PodCastDetail : Page
    {
        private NavigationHelper _navigationHelper;

        private DataTransferManager _dataTransferManager;




        public PodCastDetail()
        {
            this.InitializeComponent();
            _navigationHelper = new NavigationHelper(this);


        }

        public PodCastViewModel PodCastModel { get; private set; }

        public NavigationHelper NavigationHelper
        {
            get { return _navigationHelper; }
        }


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            _dataTransferManager = DataTransferManager.GetForCurrentView();
            _dataTransferManager.DataRequested += OnDataRequested;

            _navigationHelper.OnNavigatedTo(e);

            PodCastModel = NavigationServices.CurrentViewModel as PodCastViewModel;
            if (PodCastModel != null)
            {
                PodCastModel.ViewType = ViewTypes.Detail;
            }
            DataContext = this;


        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            _navigationHelper.OnNavigatedFrom(e);
            _dataTransferManager.DataRequested -= OnDataRequested;

        }

        private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            if (PodCastModel != null)
            {
                PodCastModel.GetShareContent(args.Request);
            }
        }




    }
}

誰か助けてくれませんか?私は本当にこれで立ち往生しています。ありがとう

4

2 に答える 2

0

現在、Windows Phone アプリと Windows ストア アプリのバックグラウンド オーディオの動作は異なることに注意してください。

電話のバックグラウンド オーディオの場合、XAML で宣言されたものを使用してはなりませんMediaElement。代わりに、バックグラウンド オーディオ タスクを使用してオーディオ作業を行う必要があります。

MSDN の Windows Phone 固有の手順に従う必要があります。これにより、理解するのに非常に役立つバックグラウンド オーディオ コードのサンプルが示されます。

于 2014-06-09T13:02:00.893 に答える