我制作了xamarin表格(PCL)的音频播放器,如下所示:
Audio.xaml(PCL):
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CPL.pages.audio">
<ContentPage.Content>
<StackLayout>
<ListView x:Name="lstSongsList" ItemSelected="lstSongsList_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label x:Name="lblFileName" Text="{Binding Name}"></Label>
<Label x:Name="lblLength" Text="{Binding Length}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Audio.xaml.cs(PCL):
private void lstSongsList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var selected = (Entity.File)e.SelectedItem;
try
{
if(selected != null)
{
Navigation.PushAsync(new player(selected));
}
}
catch(Exception ex)
{
}
}
Player.xaml.cs(PCL):
public player(Entity.File entity)
{
InitializeComponent();
_file = entity;
DependencyService.Get<iFile>().PlayFile(entity.FullPath);
}
Files.cs(机器人):
public bool PlayFile(string filePath)
{
if(currentFile != filePath)
{
if (_mediaPlayer != null)
{
_mediaPlayer.Stop();
}
_mediaPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Android.Net.Uri.Parse(filePath));
_mediaPlayer.Start();
var file = rootDirectory.GetFiles(".lrc", SearchOption.AllDirectories).FirstOrDefault();
_mediaPlayer.AddTimedTextSource(file.FullName, "application/octet-stream");
_mediaPlayer.SetVolume(100, 100);
currentFile = filePath;
}
return true;
}
它在播放和暂停时工作正常,但我无法显示addtimedTextSource文件中附加的歌词。我必须在播放歌曲时显示歌词。
任何人都有关于以xamarin形式显示音频歌词的想法吗?