0
最近,我試圖爲windows phone平臺創建名爲「Learn ABCD」的應用程序。如何在透視選項發生變化時在圖像中加載圖像後加載音頻文件
這個應用程序的主要邏輯是,最初我想加載所有的字母字符圖像像蘋果公司的B,球等等圖像的樞軸項目,同時刷每個樞軸項目,將顯示相應的字母圖像和音頻文件比如如果我滑動到B意味着那麼對應的B對於球形圖像和B對講音頻文件應該在後臺播放。
我已成功加載圖像並在使用旋轉控制滑動時播放相應的音頻文件,但問題是音頻文件在圖像顯示給用戶之前播放。我需要的是在圖像後播放音頻文件。
這裏是樞軸控件我加載圖片代碼:
XAML代碼
<phone:Pivot x:Name="pivot" ItemsSource="{Binding}" SelectionChanged="pivot_SelectionChanged" >
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Name="HeaderText" Text="" Foreground="White" ></TextBlock>
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<phone:Pivot.ItemTemplate>
<DataTemplate>
<Grid Margin="0,-50,0,0">
<Image Name="img" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="{Binding _images}" />
</Grid>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
和我的CS文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using LearnABCD.Resources;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Diagnostics;
using Microsoft.Xna.Framework.Media;
using System.Threading;
namespace LearnABCD
{
public partial class MainPage : PhoneApplicationPage
{
String[] HeadText = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
String[] alpha = new String[] { "aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo", "pp", "qq", "rr", "ss", "tt", "uu", "vv", "ww", "xx", "yy", "zz" };
String[] Galtones1 = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", "a22", "a23", "a24", "a25" };
String[] Galtones2 = { "aa0", "aa1", "aa2", "aa3", "aa4", "aa5", "aa6", "aa7", "aa8", "aa9", "aa10", "aa11", "aa12", "aa13", "aa14", "aa15", "aa16", "aa17", "aa18", "aa19", "aa20", "aa21", "aa22", "aa23", "aa24", "aa25" };
private List<TList> _pivotList;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += Pivot_Loaded;
}
private void Pivot_Loaded(object sender, RoutedEventArgs e)
{
_pivotList = new List<TList>();
for (int i = 0; i < alpha.Length; i++)
{
_pivotList.Add(new TList
{
_images = "image/" + alpha[i] + ".png",
});
}
pivot.DataContext = _pivotList;
}
private void initialize_audio()
{
int noteID1 = pivot.SelectedIndex;
for (int i = 0; i < 3; i++)
{
if (i == 0)
{
Initialize();
Song song = Song.FromUri("Petzold", new Uri("AudioABCD/" + Galtones1[noteID1] + ".mp3", UriKind.Relative));
PlaySong(song);
}
else if (i == 1)
{
Initialize();
Song song = Song.FromUri("Petzold", new Uri("image/fr.mp3", UriKind.Relative));
PlaySong(song);
}
else if (i == 2)
{
Initialize();
Song song = Song.FromUri("Petzold", new Uri("AudioABCD/" + Galtones2[noteID1] + ".mp3", UriKind.Relative));
PlaySong(song);
}
Thread.Sleep(1000);
}
}
private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
initialize_audio();
}
void Initialize()
{
MediaPlayer.Stop();
}
void PlaySong(Song song)
{
MediaPlayer.Play(song);
}
}
class TList
{
public string _images { get; set; }
}
}
圖像加載第一次加載圖像發揮它相應audio..but如果我刷卡扭轉已經加載圖像聲音不應該play..Please解決此錯誤... – rohini 2014-09-25 13:26:57
添加布爾的列表並將它們設置爲標記它們已被播放。 – 2014-09-25 13:49:04
請詳細解釋...用代碼..我不明白.. – rohini 2014-09-26 13:31:16