Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
winrt app now navigates to the video player page, and plays the video…
Browse files Browse the repository at this point in the history
… using the MediaElement
  • Loading branch information
joelmartinez committed May 22, 2012
1 parent 95f6de1 commit 8819917
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion KhanViewer.Metro/CategoryPage.xaml.cs
Expand Up @@ -36,7 +36,8 @@ private void MainListBox_SelectionChanged(object sender, SelectionChangedEventAr
return;
var item = MainListBox.SelectedItem as VideoItem;
// Navigate to the new page
item.Navigate();
//item.Navigate();
Frame.Navigate(typeof(VideoPlayer), item);

// Reset selected index to -1 (no selection)
MainListBox.SelectedIndex = -1;
Expand Down
7 changes: 7 additions & 0 deletions KhanViewer.Metro/KhanViewer.Metro.csproj
Expand Up @@ -163,6 +163,9 @@
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VideoPlayer.xaml.cs">
<DependentUpon>VideoPlayer.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand All @@ -184,6 +187,10 @@
<Content Include="Assets\StoreLogo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Page Include="VideoPlayer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CategoryPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
5 changes: 5 additions & 0 deletions KhanViewer.Metro/VideoPlayer.xaml
Expand Up @@ -36,6 +36,11 @@
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>

<MediaElement
x:Name="vid"
Grid.Row="1"
Source="{Binding VideoFileUri}"
/>
<VisualStateManager.VisualStateGroups>

<!-- Visual states reflect the application's view state -->
Expand Down
4 changes: 4 additions & 0 deletions KhanViewer.Metro/VideoPlayer.xaml.cs
Expand Up @@ -33,6 +33,10 @@ public VideoPlayer()
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var video = e.Parameter as VideoItem;
this.DataContext = video;

vid.Play();
}
}
}
6 changes: 3 additions & 3 deletions KhanViewer/ViewModels/VideoItem.cs
Expand Up @@ -30,9 +30,9 @@ public void Navigate()

App.ViewModel.TrackPageView(this.Name, "/" + this.Parent + "/Video/" + this.Name);

bool hasVideoUri = this.VideoFileUri == null || string.IsNullOrWhiteSpace(this.VideoFileUri.ToString());
bool noVideoFileUri = this.VideoFileUri == null || string.IsNullOrWhiteSpace(this.VideoFileUri.ToString());
#if !WINDOWS_PHONE
if (hasVideoUri)
if (noVideoFileUri)
{
Windows.System.Launcher.LaunchUriAsync(this.VideoUri);
}
Expand All @@ -43,7 +43,7 @@ public void Navigate()
#else
WebBrowserTask browser = new WebBrowserTask();

if (hasVideoUri)
if (noVideoFileUri)
{
browser.Uri = this.VideoUri;
}
Expand Down

0 comments on commit 8819917

Please sign in to comment.