Accessing phone gallery and camera - windows-phone-7

How to access Phone gallery and camera in windows phone7 through code

there are Launchers and Choosers which allow you to call these options and they also allow you to call other things such as map,sms compose,search etc.
here is an example of one (camera)
Creating Object
CameraCaptureTask cvt = new CameraCaptureTask();
Registering event
cvt.Completed += new EventHandler<PhotoResult>(cv_Completed);
cvt.Show();
Creating callback method
private void cv_Completed(object sender, PhotoResult r)
{//Your Code Here
}
also read here - MSDN- Launchers and Choosers

You want to see many good samples in the good Nokia Developer Windows Phone Website. They're good tutoriel with many samples.

Related

Getting AppID for Windows Phone in Unity3d

I am developing game for windows phone in unity3d, I have inserted Rate me button in game but on run time in windows phone it didn't work, is there any method to access AppID for the current application running in windows phone developed in Unity3d. I need code in unity3d CSharp for getting AppID.
I tried this C# code in Unity but It didn't work and having error no keywork found windows.
string appId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
LinkUri = new Uri("http://www.windowsphone.com/s?appid=" + appId, UriKind.Absolute)
Here I needed AppID to complete my link for rate me.
As far as i know Unity can not access the Windows namespace but you can make use of EventHandler to call 'Review Task' from Unity. You can do this by following below steps(visit Unity Expert for detailed explanation).
In Unity Game Engine-
Create Event -
using UnityEngine;
using System;
public static class events
{
//Create a new event
public static event EventHandler RateUs;
public static void FireRateUs()
{
Debug.Log ("Opening Rate Task......");
//If event is subscribed than fire it
if(RateUs!=null)
RateUs(null,null);
}
}
Fire Event -
using UnityEngine;
public class RateUs : MonoBehaviour
{
void OnMouseDown()
{
events.FireRateUs();
}
}
In Visual Studio IDE
Subscribe Event -
public MainPage()
{
.
.
.
.
events.RateUs += events_RateUs;
}
Call Function -
void events_RateUs(object sender, EventArgs e)
{
String AppId = Windows.ApplicationModel.Store.CurrentApp.AppId.ToString();
Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + AppId));
}
You have to get your AppID from your developer's portal on Microsoft Create's web page. You can then hardcode it into your app or save it as a static/globally available variable for accessing purposes. This would mean you would have to begin the process of creating your app entry prior to the programming of the rating game feature. Just create the entry, and don't submit it! Or create it, and add Rate app as an update. I'd choose the former method, personally!
For Apple and Google rating/submit information you have to create the entry ahead of time to get a SKU number. Also in iTunes/Apple/iOS/OSX you have to create the app and give it a unique name, etc in the developer's portal/certificate store.

restrict the windows phone app for specific devices

i want my application should work on specific devices\OS like "Lumia 650"\"windows phone 8", this is my project requirement.
Is it possible ? if yes where should I mention the details ?
It is not a problem to restrict Windows Phone 8. You just need to build it targeting Windows Phone OS 8.0.
For the device model you do something like this in the App.xaml.cs
private void Application_Launching(object sender, LaunchingEventArgs e)
{
var deviceName = DeviceExtendedProperties.GetValue("DeviceName").ToString();
if (!deviceName.Contains("Lumia_650")) // Please check your phone's actual value
Application.Current.Terminate();
}
If you want to show a friendly message before it exits you can move the code to the MainPage.xaml.cs then add the MessageBox.Show(message) part.
This is only possible in code as you can not prevent users from installing the app if the app is meant for that particular OS what that user has. However, once the app is launched you can get the name of the device and do actions accordingly.
You can try this:
var PhoneName = Microsoft.Phone.Info.DeviceStatus.DeviceName;
if(PhoneName == "Not Allowed Phone")
{
MessageBox.Show("You can not use this app");
}
else
{
}

Windows Phone leave background music playing

My Windows Phone app was rejected because when I play a sound in the browser in my app it stops existing background music from playing (rejection issue 6.5.1).
How do I update my application to not stop background music?
My JavaScript is something like this:
var mySound = new Audio(soundpath);
Sound.play(mySound);
I could not find anything in Microsoft.Xna.Framework.Media that handles how the app handles browser sound, but maybe I missed something?
What you are looking for is from the xna soundeffect
Here is what I use and it works for me great for all my sound effects.
(You cannot use music with a 'soundeffect' object, as it will not pass the windows store qualifications. You have to use the MediaElement for music)
I can’t remember which you need but I have all these includes
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
and this function
private static void LoadSoundEffect(string fileName, SoundEffectInstance mySound)
{
var stream = TitleContainer.OpenStream("Sounds/" + fileName);
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
mySound = effect.CreateInstance();
}
If you use a SoundEffectInstance, you can start,pause,stop the soundeffect etc. without all the problems.
SoundEffect works as well, but I prefer the SoundEffectInstance.
Edit: If you use soundeffect, it will not effect the music being played.
I'm assuming that you are building a native Windows Phone app (.XAP) and then using a browser control to display your app content. If that is the case, you have checks that you will need to perform when the app is first opened. Below is a description of how to resolve that issue.
You will need to add this piece of code to your app (I suggest you check this every time your app loads/opens). Add a reference with the using statement as well for the Media.
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{
MessageBoxResult Choice;
Choice = MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel);
if (Choice == MessageBoxResult.OK)
mediaElement1.Play();
}
If the user allows or disallows the media to be played you must put checks in your JavaScript for this. You will fail certification again if the user says "Cancel" and you play music anyway.
There is more information on the topic here.

Extrading Metadata of an audio streaming file (MediaElement)

I just started to develop for the Windows Phone (7.1/8) platform and am still not really familiar with it.
My plan is an internet radio app which streams the audio file from a server. I used MediaElement to set the source property to the streaming URL.
It works and the app starts playing the music but I can't read any metadata about the song which is coming from the server such as artist name/title or any string which I can use to know about the song itself.
I've been searching around and tried the MediaReached event as well, but it never gets fired as well?
So any idea what should I do?
and My Code Behind Sample:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyMedia.Source = new Uri("MyURL");
}
I hate to tell you this but it is because the MediaElement.Attributes are not supported for Windows Phone 7 - all the limitations can be found here: http://msdn.microsoft.com/en-us/library/ff426928(VS.95).aspx

Display Camera output in Windows Phone 7

I'm writing an augmented reality app for Windows Phone 7 as a school project. I want to get the camera output and then add a layer of data over it. Is there a way to have the camera output displayed in a panel?
FYI: In Windows Phone SDK 7.1 (a.k.a. "Mango") you can now write apps that use the device camera as you describe. See App Hub for a link to the latest 7.1 development tools. The documentation describes how to do this at the following link:
How to: Create a Base Camera Application for Windows Phone
But basically, add a videobrush to display the camera feed (a.k.a. the "viewfinder"). For example, here a rectangle control is used display the camera viewfinder:
<!--Camera viewfinder >-->
<Rectangle Width="640" Height="480"
HorizontalAlignment="Left"
x:Name="viewfinderContainer">
<Rectangle.Fill>
<VideoBrush x:Name="viewfinderBrush" />
</Rectangle.Fill>
</Rectangle>
To use the camera in the code-behind for the page, add a reference to Microsoft.XNA.Framework and put the following Using statements at top of the page:
// Directives
using Microsoft.Devices;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework.Media;
Note: you may not need all of these, I just copied it from the docs. In Visual Studio (Pro, at least), you can clean them up after you're done by right-clicking your code file and clicking: Organize Usings | Remove Unused Usings.
Then, basically you apply the camera image to the rectangle in the OnNavigatedTo handler...
//Code for initialization and setting the source for the viewfinder
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Initialize camera
cam = new Microsoft.Devices.PhotoCamera();
//Set the VideoBrush source to the camera.
viewfinderBrush.SetSource(cam);
}
...and dispose of the camera object in the OnNavigatingFrom.
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
// Dispose camera to minimize power consumption and to expedite shutdown.
cam.Dispose();
// Good place to unhook camera event handlers too.
}
The 7.1 docs also describe an augmented reality app in the following topic. Note that you'll need to scroll-down to the section titled Creating a Silverlight-based Augmented Reality Application, to find the instructions for building it with Mango.
How to: Use the Combined Motion API for Windows Phone
Hope that also helps others seeking information about PhotoCamera in Windows Phone OS 7.1.
Cheers
According to Microsoft's UI Design and Interaction Guide [PDF], They do not allow developers to access the camera with any UI Elements.
This comes from page 127:
There are no direct UI elements
associated with the Camera, but
developers have access to the Camera
in the Microsoft.Phone.Tasks
namespace.
As of today (1/19/2010) you only officially have access to photos taken using the CameraCaptureTask. If you do not plan to submit your application to the marketplace then you can use the PhotoCamera class from the Microsoft.Phone.Media.Extended namespace as outlined by Dan Ardelean and Kevin Marshall. See this post for a video demo and his blog for more details. Please note that your application will not pass marketplace certification if you use these assemblies as they are not part of the official SDK.
The short answer to your question is: no.
You can capture photos using the CameraCaptureTask provided by the Windows Phone 7 API (here), but, to the best of my knowledge, you cannot capture a live stream of data from the camera.
Microsoft has not announced whether this functionality will be augmented in a future release of the platform.
Example of using CameraCaptureTask:
public partial class MainPage : PhoneApplicationPage
{
// Declare the CameraCaptureTask object with page scope.
CameraCaptureTask cameraCaptureTask;
// Constructor
public MainPage()
{
InitializeComponent();
// Initialize the CameraCaptureTask and assign the Completed handler in the page constructor.
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
}
// In this example, the CameraCaptureTask is shown in response to a button click.
private void button1_Click(object sender, RoutedEventArgs e)
{
cameraCaptureTask.Show();
}
// The Completed event handler. In this example, a new BitmapImage is created and
// the source is set to the result stream from the CameraCaptureTask
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;
}
}
}
As noted here, we're limited to CameraCaptureTask Functionality for the moment.
Information has been released recently to indicate functionality to support AR is on the roadmap.

Resources