mediaelement in windowsphone8.1 stop working - windows-phone-7

I'm using mediaelement in my windows phone 8.1 app. I have some others button too. When I use buttons it's a link to a website. When I use back button to back to my mainpage the mediaelement stop working. What can I do?
//this is my media element in xaml
<MediaElement x:Name="nima" Source="assets/jadid.mp3" AutoPlay="True"/>
I even use:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
nima.Play();
}
But it's not working. Please help me.

If you want to play audio when your application is not in the foreground then you need to create a Background Audio Task and include that inside your solution.
See MSDN: Background Audio for Windows Phone 8.1 Sample for complete tutorial and project files.

Related

Hold gesture to save image to media library

I'm trying to work something out and can't seem to get the final piece together. I have a Windows Phone app that displays images from Flickr and what I want to do is allow the user to save the image that is on the phone screen to their Media Library. I've employed the Hold Gesture to do this and I need some help getting the context menu to pop-up after the user holds down on the image. I'm not sure how to get the menu to pop up. Here is the Hold-Code I'm trying to use. There is something I'm missing here.
private void Image_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
var img = sender as System.Windows.Controls.Image;
var url = (string)img.Tag;
}
Thanks for any help.
It is possible to save an Image to the MediaLibrary on Windows Phone 7 and 8.
There are...
Blogs with code snippets
MSDN documentation
Lots of previous answers on Stackoverflow.

Why is video button grayed out in Windows Phone 7 camera chooser task?

I'm wondering why the video capture button is always grayed out (disabled) when using the both the Camera Capture Task and the Photo Chooser Task with ShowCamera = true;?
I've tried to find ways to enable it, but without any success.
I'm developing for Windows Phone 7.5.
Thank you in advance!
It's greyed out because Camera Capture and Photo Chooser both only support single images, not videos.
If you're looking to capture video, take a look on MSDN here:
http://msdn.microsoft.com/en-us/library/hh394041(v=VS.92).aspx
Actually you can :). Here is the tutorial for that:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394041(v=vs.105).aspx
And to download complete sample click here
http://code.msdn.microsoft.com/wpapps/Video-Recorder-Sample-5e800bbf

Back button PhoneGap Windows Phone 7

While certifiying my Phonegap App for Windows Phone 7 I was told that the back-button doesn't work the way it should. My application only has one page, so here it's not a problem but it is possible to display a menu using javascript.
When this menu is open, the back-button is supposed to close the menu instead of exiting the application. Does anyone have an idea on how I could easily catch the event of a click on the back-button in order to check if the menu is open and then close it or completely exit the application if it isn't?
I tried document.addEventListener("backbutton", onBackKeyDown, false); but apparently this does not work for Windows Phone 7!
Thanks a lot
WP7 PhoneGap definitely supports the back button. You can download a working example from my blog here:
http://www.scottlogic.co.uk/blog/colin/2011/11/handling-the-back-stack-in-windows-phone-7-phonegap-applications/
Make sure you handle the deviceready event first.
Why don't you use the native Silverlight.
XMAL
BackKeyPress="PageBackKeyPress"
Code-Behind
private void PageBackKeyPress(object sender, CancelEventArgs e)
{
// DO NOT CLOSE
if (Something)
e.Cancel = true;
}
I have the same problem. When you write
document.addEventListener("backbutton", onBackKeyDown, false);
That will block the the default backbutton handler. So you may need to do so tricks in the phonegap code. It's not the best way, but it's quite easy though. Check out this one:
http://blog.projectdebug.com/?p=6

How to simulate the hardware shutter button in the Emulator?

In addition to soft keys, I'd like to test how my app responds to the hardware shutter buttons (e.g. various states half-pressed, fully-pressed, button-release. etc...).
The emulator does not seem to have a hardware shutter button (unless I am missing something).
So, in the absence of an actual device, how can I test this functionality?
The F7-Key is mapped in the emulator to the camera shutter-key fully pressed and the F6-Key is mapped to the half-pressed shutter-key.
Both shortcuts are not supported in Visual Studio 2010 Express for Windows Phone (but I have no idea why they did this limitation...)
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff754352%28v=vs.105%29.aspx gives a list of supported emulator hot-keys. :)
You could have specific buttons in your application and simply invoke the method wired to the event handler. For example:
// Constructor
public MainPage()
{
InitializeComponent();
CameraButtons.ShutterKeyHalfPressed +=new EventHandler(CameraButtons_ShutterKeyHalfPressed);
CameraButtons_ShutterKeyHalfPressed(this, new EventArgs());
}
void CameraButtons_ShutterKeyHalfPressed(object sender, EventArgs e)
{
Debug.WriteLine("HALF_PRESSED");
}
But that would only help if you are willing to have a dedicated "test panel" in your application that will control these events.
As with everything else hardware related, you kinda can't ;-) So hurry on the mailman to deliver your phone already!

Working with Windows Phone 7, how do I create a global MediaElement?

I need to create a MediaElement that will keep playing when I navigate to different pages within my app. Any ideas on how to do this?
I actually just found a solution. As so often before once you write down a question you get an idea that works yourself :)
private MediaElement _mediaElement;
...
_mediaElement = new MediaElement {Volume = 1, AutoPlay = false};
var _pop = new Popup {Child = _mediaElement, IsOpen = true};
This works - in case anybody else runs into the same problem...
I don't think that is possible.
MediaElement is a UIElement which must be hosted inside a page to work.
Each time you navigate, a new page instance is loaded in WP7. A really ugly hack might work, but I don't recommend it.
What are you trying to do?
You could remember the position it was at and restart it when back on page.
If you want to have music that will play throughout an application, consider using the MediaPlayer class.
Alternatively you re-template the PhoneApplicationFrame and put it there. I'm using this solution in my app and I like it better than the popup solution because you can layout the mediaelement along with everything else (like the appbar) if you want controls and stuff.
I had a similar problem and I post on my blog a soltuion.
Silverlight for Windows Phone 7 is based on the page navigation system. Key point is the lifetime of pages – each page is deleted while you navigate to another. To have an object - a singleton for example - during the whole application life it could be placed in App class (App.xaml.cs file). MediaElement is definitely an object that should be one (there must be only one music player). The best and simple solution is place the MediaElement in XAML(it needs to be a part of visual tree), I have used application resources:
<!--Application Resources-->
<Application.Resources>
<MediaElement x:Name="mediaPlayer" Source="/Sound/horrorSong.mp3" AutoPlay="False" />
</Application.Resources>
Then to get it from any page use resources as a dictionary:
MediaElement player = null; // get the media element from App resources
if (App.Current.Resources.Contains("mediaPlayer"))
{
player = App.Current.Resources["mediaPlayer"] as MediaElement;
}
if (player != null)
{
player.Play();
}
It is worth notice that MediaElement can’t play the music while Zune is connect. It is a good idea to prompt the user about it. In a method
if (NetworkInterface.GetIsNetworkAvailable())
{
if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
zuneTextBlock.Visibility = System.Windows.Visibility.Visible;
return;
}
}
zuneTextBlock.Visibility = System.Windows.Visibility.Collapsed;
This code does not guarantee if Zune is on (User still could have the phone plugged) but is very likely that Zune is running(Zune starts while phone is connecting).
I found this solution: http://www.jayway.com/2010/10/04/enable-background-audio-for-multiple-pages-in-windows-phone-7/
Works on WP8.

Resources