I am trying to play a video in my app. The video and the xaml file are present under the same folder.
My xaml code (which is a user control)
<Grid x:Name="LayoutRoot">
<MediaElement x:Name="vid" MediaOpened="MediaElement_MediaOpened"
Source="hey.mp4" AutoPlay="True" />
</Grid>
My xaml.cs file code
public Page1()
{
InitializeComponent();
}
private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
vid.Play();
}
The video is not playing. I tried the source to be "/hey.mp4" also, but it didn't play.
What is my mistake ?
Check your URl of the video and to disable locking of the phone, you could do this,
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
Related
I'm making a simply UWP (Universal Windows 10 App) web app using a webview.
How can I return on the top of the page clicking on a button?
I can't find it on the MSDN.
You can use window.scrollTo(0,0) method, it is a JavaScript method that scrolls the document to position "0" horizontally and "0" vertically.
You can interact with the content of the WebView by using the InvokeScriptAsync method to invoke or inject script into the WebView content.
For example:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView x:Name="theWebView" Source="https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.aspx">
</WebView>
<Button Content="To The Top" Click="Button_Click"></Button>
</Grid>
Code behind:
private string ScrollToTopString = #"window.scrollTo(0,0);";
private async void Button_Click(object sender, RoutedEventArgs e)
{
await theWebView.InvokeScriptAsync("eval", new string[] { ScrollToTopString });
}
Hi guys I have added a video to my application that plays automatically when the page loads and when the video is double tapped it goes to full screen. Here is my code.
c#
private void mediaSimple_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
mediaSimple.IsFullWindow = true;
}
xaml
<MediaElement x:Name="mediaSimple" Source="ms-appx:///Videos/1-Learning-how-to-manage-things-yourself.mpg" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoPlay="True" DoubleTapped="mediaSimple_DoubleTapped" />
What can I add to my code guys to allow me to exit full screen mode when I touch the screen of my device?
Modify your code like this :
mediaSimple.IsFullWindow = !mediaSimple.IsFullWindow;
I'm trying to create a page in my app which will show simple text updates, and I'm planning on using a browser window to show this, so, to put it simply I want a browser windows within the app that will only show one page, I don't want the user to be able to navigate to another site.
I've got the browser window added in XAML like so:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser HorizontalAlignment="Left" Margin="12,6,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="595" Width="438"/>
</Grid>
I've then got this in the C# file:
private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
{
//SaveFilesToIsoStore();
webBrowser1.Navigate(new Uri("http://www.nokia.ie/"/*, UriKind.Relative*/));
}
Basically, first of all, am I doing this the right way, and if so, how do I get the browser to display the web page?
Thanks.
listen to the browser navigation and stop navigation to any sites that you haven't defined
private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
{
webBrowser1.Navigate(new Uri("http://www.nokia.ie/"));
webBrowser1.Navigating += OnNavigating;
}
private void OnNavigating(object sender, NavigatingEventArgs e)
{
//every navigation to any sites that is not www.nokia.ie will be blocked
if(e.Uri.OriginalString != "http://www.nokia.ie/")
{
e.Cancel=true;
}
}
I am programming in C# for Windows Store apps but i am new to this platform. In my application i want to implement the share contract option when user click the Share button from Charm Bar.
I could see only SettingsPane and SearchPane API to access Settings and Search options but was not able to find anything with the name of SharePane. Is there any way to access the Share click handling in Windows Store apps ?
Here I am showing you the basic usage of share charm. In my example we will share text content from text box
DataTransferManager class does all the sharing. So first you will need the current instance of that class and invoke DataRequested event. So you have to assign event in OnNavigatedTo event & release event in OnNavigatedFrom event.
If you want to open share charm programmatically then write DataTransferManager.ShowShareUI(); in button's click event.
Code for the sample.
C#
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
dataTransferManager.DataRequested += ShareTextHandler;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
dataTransferManager.DataRequested -= ShareTextHandler;
}
private void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share Text Example"; // You must have to set title.
request.Data.Properties.Description = "A demonstration that shows how to share text.";
request.Data.SetText(ShareText.Text);
}
private void Share_Click_1(object sender, RoutedEventArgs e)
{
DataTransferManager.ShowShareUI();
}
XAML
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<TextBox Width="500" Height="200" x:Name="ShareText" />
<Button Content="Share" Click="Share_Click_1" HorizontalAlignment="Center" />
</StackPanel>
</Grid>
MSDN Sample App
Quickstart: Sharing content (Windows Store apps using C#/VB/C++ and XAML)
Here I am pasting the code. My app has capability to access music library. I am not getting any exception but media file is not being played after navigation. Here is the project hosted on skydrive
MainPage.xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Click Me" Margin="563,357,0,373" Click="Button_Click_1"></Button>
</Grid>
MainPage.xaml.cs
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFile file = await KnownFolders.MusicLibrary.GetFileAsync("video.mp4");
Frame.Navigate(typeof(MediaPlayback), file);
}
MediaPlayback.xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<MediaElement x:Name="MyMediaPlayback" Height="350" Width="640"/>
</Grid>
MediaPlayback.xaml.cs
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
StorageFile file = e.Parameter as StorageFile;
try
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
MyMediaPlayback.SetSource(stream, file.ContentType);
MyMediaPlayback.Play();
}
catch (Exception)
{
throw;
}
}
A common problem with OnNavigatedTo is that it gets called before Loaded event fires, which is when the control actually gets added to the visual tree. I am only guessing, but you might need to wait for the page to load before calling .Play(). Also I think by default MediaElement is set up to play automatically when you set the source, so calling Play might be unnecessary or in fact it could be what breaks here. MediaElement still has many basic bugs in Windows 8 RTM and needs to be used carefully to work around them. This would also be an excellent use case for a call to "await WaitForLoadedAsync()" to see if waiting for that event is necessary instead of hunting for the navigation parameter in the Loaded event handler.