Accessing Pictures from Media Library in Windows Phone

You may come across a requirement to access the entire picture saved in Media Library of Windows Phone. Media Library can be access using MediaLibrary class.

To work with MediaLibrary class you need to add reference of Microsoft.Xna.Framework. This class is defined in namespace Microsoft.Xna.Framework.Media namespace.

To work with MediaLibrary, you need to make instance of MediaLibrary class as below,

image

Pictures property of MediaLibrary class returns all the images as Picture. You can iterate to all images as below,

image

Image can be fetch as stream inside foreach look as below,

image

You can create Image from returend stream as below.

image

Eventually you can set imageToShow as source of Image control. For your reference below code will add all the pictures from Media Library in a listbox called lstImageFromMediaLibrary


MediaLibrary m = new MediaLibrary();

foreach (var r in m.Pictures)
{
Stream imageStream = r.GetImage();

var imageToShow = new Image()
{
Source = PictureDecoder.DecodeJpeg(r.GetImage())
};

lstImageFromMediaLibrary.Items.Add(imageToShow);
}
}


You can access Media Library on emulator only in debugmode. In this way you can access all the images from Media library. I hope this post is useful. Thanks for reading.

 

Code to send game invite to multiple user in Windows Phone

You can send game invite to multiple users in Windows Phone using GameInviteTask chooser.

GameInviteTask chooser is used to send invitation to other users in multi-player game. It provides an invite screen to user where they can configure Email address of other users to send game invitation. Invitation will be sent by GameInviteTask chooser is in asynchronous manner.

GameInviteTask will launch invite screen and when user will complete configuring Email address of other user then complete event will get fired.

To work with GameInviteTask, you need to follow below steps

Very first you need to declare variable globally on the page as below,

image

Then Create instance of GameInviteTask and attach completed event in the constructor of the page as below,

image

Next you need to call the show method to launch invite screen application as per your business requirement. It may be on click event of a button. Session Id is string identifying particular network session.

image

In completed event handle user action. On selection of user shown appropriate message as below,

image

User will configure Email Id as below,

image

On user selection cancel, message will be shown in message box as below.

image

For your reference full source code is as below,



public partial class MainPage : PhoneApplicationPage
{
GameInviteTask gameInviteTask;

public MainPage()
{
InitializeComponent();
gameInviteTask = new GameInviteTask();
gameInviteTask.Completed += new EventHandler<TaskEventArgs>(gameInviteTask_Completed);

}

private void Button_Click(object sender, RoutedEventArgs e)
{
gameInviteTask.SessionId = "your session id of the game";


}

void gameInviteTask_Completed(object sender, TaskEventArgs e)
{
switch (e.TaskResult)
{

case TaskResult.OK:
MessageBox.Show("Sent");
break;

case TaskResult.Cancel:
MessageBox.Show("Cancel");
break;

case TaskResult.None:
MessageBox.Show("Failed");
break;
}
}
}


In this way you can send game invitation to multiple users. I hope this post is useful. Thanks for reading.

Launchers related to MarketPlace in Windows Phone

In this post we will discuss three important launchers related to Windows Phone Market Place

  • MarketPlaceHubTask launcher
  • MarketPlaceReviewTask launcher
  • MarketPlaceDetailTask launcher

MarketPlaceHubTask launcher

This is used to launch Windows Phone Market Place client application. You can launch market place client application along with music content as below,


MarketplaceHubTask marketplaceHubTask = new MarketplaceHubTask();
marketplaceHubTask.ContentType = MarketplaceContentType.Music;
marketplaceHubTask.Show();

You can set content type of the search either as Application or Music. MarketPlaceContentType is defined as below,

clip_image002

Market place client application will be launched as below,

clip_image003

MarketPlaceReviewTask launcher

This is used to launch market place client application with review page. Market place application review page can be launched as below,



MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();

It will ask user confirmation for Submit or Cancel. It will ask user confirmation for Submit or Cancel. After selecting submit option user will be redirected to review page of market place application.

MarketPlaceDetailTask launcher

This is used to launch market place client application with details page of specified application. You need to pass unique content identifier of application to get detail page of the application from market place. If you don’t set unique content identifier then detail page of current application will be launched in windows phone market place client application.

You can launch detail page of current application as below,


MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
marketplaceDetailTask.ContentType = MarketplaceContentType.Applications;
marketplaceDetailTask.Show();

You can launch detail page of a specific application by passing content identifier.

These are three important launchers for market place client application and you may use them frequently in your application. I hope this post is useful. Thanks for reading.

WebBrowserTask and MediaPlayerLauncher in Windows Phone

In this post, we will see WebBrowserTask launcher and MediaPlayer launcher.

WebBrowserTask launcher launches web browser application and display specified URL. This is defined as below,

image

You can set target URL either as string or as Uri. User will be asked for the confirmation. You can navigate to a URL as below,



WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://debugmode.net", UriKind.Absolute);
webBrowserTask.Show();

On running you will be navigated to given URL as below,

image

MediaPlayerLauncher is used to launch media player application and play the video from specified URL. This class is defined as below,

image

You can set desired controls of media player to be shown to user. Available media player controls are as below.

image

If you want to show more than one control to the user then you need to append them using OR operator and set them as value of control property.

image

You can also specify location of the media file in MediaLocationType property. MediaLocationType takes one of three values.

 

image

 

Install represents application installation directory, Data represents isolated storage and None value need to be set for external media.

You can play media with file from isolated storage as below,



MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();

mediaPlayerLauncher.Media = new Uri("SongVideo.wmv", UriKind.Relative);
mediaPlayerLauncher.Location = MediaLocationType.Data;
mediaPlayerLauncher.Controls = MediaPlaybackControls.Pause |
MediaPlaybackControls.Stop|
MediaPlaybackControls.FastForward;
mediaPlayerLauncher.Orientation = MediaPlayerOrientation.Landscape;

mediaPlayerLauncher.Show();

In this way you can work with MediaPlayerLauncher.

In this post we discussed on WebBrowserTask and MediaPlayerLauncher. You may need to call these native applications from your app. I hope this post is useful. Thanks for reading.

Code to search location on Bing Map

BingMapTask launcher is used to search a location and mark it on the Bing map. It is defined as below,

image

Search term need to be set as string. If geo coordinate of center is not provided then BingMapTask will search a location on basis of user’s current location.

Hospitals can be located and marked on the Bing map from user’s current location as below,


BingMapsTask bingMapsTask = new BingMapsTask();
bingMapsTask.SearchTerm = "hospital";
bingMapsTask.ZoomLevel = 2;
bingMapsTask.Show();

You can set the zoom level of the map as well. In this way you can search a location and mark that on Bing map.

I hope this post is useful. Thanks for reading.

MarketPlaceSearchTask in Windows Phone

MarketPlaceSearch Task launcher is used to launch Marketplace client application with the searched result set in the criteria. It helps to search to marketplace from the application.

MarketPLaceSearchTask is defined as below,

image

You can see in the definition that, you can set MarketplaceContentType and SearchTerms. MarketPlaceContentType is defined as below,

image

So it can take either Application or Music as value. Now if you want to search music in market place then you can do that as below,


MarketplaceSearchTask task = new MarketplaceSearchTask();
task.ContentType = MarketplaceContentType.Music;
task.SearchTerms = "Waiting for Tonight";
task.Show();


You will get Market place search application launched as below,

image

If you want to search any application like debugmode , you can search as below,


MarketplaceSearchTask task = new MarketplaceSearchTask();
task.ContentType = MarketplaceContentType.Applications;
task.SearchTerms = "debugmode";
task.Show();


You will get Market place search application launched as below,

clip_image001[6]

In this way you can use MarketPlaceSearchTask. I hope this post is useful. Thanks for reading.

 

Clipboard API in Windows Phone

In this post we will see Clipboard API support in Windows Phone. Clipboard API support came as part of Windows Phone 7.5 and it was not part of Windows Phone 7.

Class is defined in System.Windows namespace as below,

clip_image002

You can set text as below,

clip_image004

In above snippet txtSource is a text box. You can check whether clipboard has some data or not as below,

clip_image006

One very important point you need to keep in mind that you cannot use GetText() method in Windows Phone. If you try to do that you will get security exception as below,

clip_image007

For security reason access to clipboard data is prohibited in Windows Phone. In this way you can use Windows Phone Clipboard API. I hope this post is useful. Thanks for reading .

 

Code to Share Status or Links on Social Media sites in Windows Phone

While creating application for Windows Phone you may come across requirement to share certain message from your application on social media sites configured on user device. You can do it using ShareStaus Task. ShareStausTask class is defined as below. It is inherited from ShareTaskBase class.

image

 

ShareStatus Task Launcher allows an application to launch a dialog that allows user to share status message on social network site.

A status message can be shared as below,


ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = "Hey I am Shared By DebugMode";
shareStatusTask.Show();


You may come across other scenario where you may need to share HyperLink across Social Media sites from your application. You can do that using launcher ShareLinkTask.

ShareLinkTask class is defined as below,

image

ShareLink Task Launcher allows an application to launch a dialog that allows user to share links on social network site.

A link can be shared as below,



ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "DebugMode";
shareLinkTask.LinkUri = new Uri("http://debugmode.net", UriKind.Absolute);
shareLinkTask.Message = "Post of DebugMode.";
shareLinkTask.Show();

These launchers will be launched only if user has configured social media sites on their device. I hope this post is useful. Thanks for reading.

How to Use the ConnectionSettings Task for Windows Phone

ConnectionSettings Task allows user to set and adjust device network settings. ConnectionSettings task is defined in Microsoft.Phone.Tasks namespace as below,

image

User can set device network setting to any of the following

image

If you want to set Network connection setting to WiFi, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Bluetooth, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Cellular, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Cellular;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Airplane mode, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.AirplaneMode;
connectionSettingsTask.Show();


image

In this way you can set the network setting of device using ConnectionSettings task. I hope this post is useful. Thanks for reading