C# 旋转木马视图中的视频问题
嘿,所以我在每个牢房里都设置了一个带视频的旋转木马C# 旋转木马视图中的视频问题,c#,listview,xamarin,C#,Listview,Xamarin,嘿,所以我在每个牢房里都设置了一个带视频的旋转木马 <CarouselView x:Name="TheCarousel"> <CarouselView.ItemTemplate> <DataTemplate> <StackLayout HorizontalOptions="Center">
<CarouselView
x:Name="TheCarousel">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout
HorizontalOptions="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="6*"/>
</Grid.RowDefinitions>
<Label FontSize="Title" HorizontalOptions="Center" HorizontalTextAlignment="Center" Text="{Binding Name}" VerticalOptions="Center" />
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Grid.Column="1">
<video:VideoPlayer Source="{Binding Uri}" HeightRequest="480"/>
</StackLayout>
</Grid>
</Grid>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
它工作正常,视频播放,但是当我滚动到另一个视频时,前一个视频会自动播放。例如,如果暂停第一个视频,然后滚动到第二个视频,第一个视频将开始播放。我不知道为什么会这样
任何帮助都将不胜感激。不知道您使用的是哪个视频播放器,但我使用的是辛烷值.Xamarin.Forms.videoplayer,没有这个问题
<CarouselView x:Name="TheCarousel" ItemsSource="{Binding videos}">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="Center">
<Label
FontSize="Title"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="{Binding title}"
VerticalOptions="Center" />
<o:VideoPlayer
AutoPlay="True"
DisplayControls="True"
FillMode="ResizeAspectFill"
Source="{Binding path}" />
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
public partial class Page5 : ContentPage
{
public ObservableCollection<videomodel> videos { get; set; }
public Page5()
{
InitializeComponent();
videos = new ObservableCollection<videomodel>()
{
new videomodel(){path="https://sec.ch9.ms/ch9/a7e9/abda3d53-bed3-4f20-9f53-70047a35a7e9/Xamarin101WhatIsXamarin_high.mp4",title="title 2"},
new videomodel(){path="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4",title="title 1"},
new videomodel(){path="https://sec.ch9.ms/ch9/3901/c6e0e4e6-bb93-4033-a484-040a874f3901/Xamarin101XamarinFormsMVVMXAML_high.mp4",title="title 3"}
};
this.BindingContext = this;
}
}
public class videomodel
{
public string path { get; set; }
public string title { get; set; }
}
公共部分类第5页:内容页
{
公共可观察收集视频{get;set;}
公共网页5(
{
初始化组件();
视频=新的ObservableCollection()
{
新建videomodel(){path=”https://sec.ch9.ms/ch9/a7e9/abda3d53-bed3-4f20-9f53-70047a35a7e9/Xamarin101WhatIsXamarin_high.mp4,title=“title 2”},
新建videomodel(){path=”https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4,title=“title 1”},
新建videomodel(){path=”https://sec.ch9.ms/ch9/3901/c6e0e4e6-bb93-4033-a484-040a874f3901/Xamarin101XamarinFormsMVVMXAML_high.mp4,title=“title 3”}
};
this.BindingContext=this;
}
}
公共类视频模型
{
公共字符串路径{get;set;}
公共字符串标题{get;set;}
}
}