Windows Phone development (26): mediaplayerlauncher and searchtask for starters and selectors

Source: Internet
Author: User

What's simple about starters and selectors is that they use almost exactly the same method. From the previous sections, I believe everyone knows how to use them.
Here, let's take a few actions. The steps for using the starter and Selector are as follows:
1. instantiate a new instance;
2. Prepare parameters and assign values to relevant attributes;
3. show;
4. This step is not required for the initiator, but the selector has returned data, so the event must be handled.

In this section, we will give two examples, the starter and the selector can be completed, and then we will start from the next section to explore new knowledge points.

Example 1: Media Player.

 

This is a starter, which is more convenient to use.
Main attributes include:
Controls -- display a control button, such as a temporary set or stop. It is an enumeration with the flags feature, so multiple values can be merged, such as mediaplaybackcontrols. Pause | mediaplaybackcontrols. Stop

Location -- the position of the media to be played. data indicates that the file is stored in an independent storage, and install indicates that the media file in the project is saved;

Media -- URI of the file to be played;

Orientation-this is a better understanding of the concept of horizontal or vertical Media Player and page direction.

 

<Phone: phoneapplicationpage <br/> X: class = "sampleapp. mainpage "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.microsoft. COM/expression/blend/2008 "<br/> xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "<br/> MC: ignorable =" D "D: designwidth =" 480 "D: designheight = "768" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" portrait "orientation =" portrait "<B R/> shell: systemtray. isvisible = "true"> </P> <p> <! -- Layoutroot is the root mesh that contains all page content --> <br/> <grid X: Name = "layoutroot" background = "Transparent"> <br/> <grid. rowdefinitions> <br/> <rowdefinition Height = "Auto"/> <br/> <rowdefinition Height = "*"/> <br/> </grid. rowdefinitions> </P> <p> <! -- Titlepanel contains the application name and page title --> <br/> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <br/> <textblock X: name = "applicationtitle" text = "my application" style = "{staticresource phonetextnormalstyle}"/> <br/> <textblock X: name = "pagetitle" text = "Page name" margin = "9,-7,0, 0 "style =" {staticresource phonetexttitle1style} "/> <br/> </stackpanel> </P> <p> <! -- Contentpanel-place other content here --> <br/> <grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 126 "> <br/> <button content =" Start Media Player "Height =" 31,116 "horizontalalignment =" Left "margin =, 381 "name =" button1 "verticalignment =" TOP "width =" "Click =" button#click "/> <br/> </GRID> </P> <p> </phone: phoneapplicationpage>
Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. net; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. animation; <br/> using system. windows. shapes; <br/> using Microsoft. phone. controls; <br/> using Microsoft. phone. tasks; </P> <p> namespace sampleapp <br/> {<br/> Public partial class mainpage: phoneapplicationpage <br/>{< br/> // constructor <br/> Public mainpage () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void button#click (Object sender, routedeventargs e) <br/>{< br/> mediaplayerlauncher player = new mediaplayerlauncher (); <br/> player. controls = mediaplaybackcontrols. all; <br/> player. location = medialocationtype. install; <br/> player. media = new uri ("fenfeiyan", urikind. relative); <br/> player. orientation = mediaplayerorientation. portrait; <br/> player. show (); <br/>}< br/>}

 

 

 

 

Example 2: search for a task.

 

The searchtask class is also a starter. This guy is simpler. It has only one attribute to set -- searchquery, which is the keyword we want to search.

<Phone: phoneapplicationpage <br/> X: class = "sampleapp. page1 "<br/> xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "<br/> xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "<br/> xmlns: Phone =" CLR-namespace: Microsoft. phone. controls; Assembly = Microsoft. phone "<br/> xmlns: shell =" CLR-namespace: Microsoft. phone. shell; Assembly = Microsoft. phone "<br/> xmlns: D =" http://schemas.microsoft.com /Expression/blend/2008 "<br/> xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006" <br/> fontfamily = "{staticresource phonefontfamilynormal}" <br/> fontsize = "{staticresource quota}" <br/> foreground = "{staticresource phoneforegroundbrush} "<br/> supportedorientations =" Landscape "orientation =" Landscape "<br/> MC: ignorable = "D" D: designheight = "480" D: designwidth = "728" <br /> Shell: systemtray. isvisible = "true"> </P> <p> <! -- Layoutroot is the root mesh that contains all page content --> <br/> <grid X: Name = "layoutroot" background = "Transparent"> <br/> <grid. rowdefinitions> <br/> <rowdefinition Height = "Auto"/> <br/> <rowdefinition Height = "*"/> <br/> </grid. rowdefinitions> </P> <p> <! -- Titlepanel contains the application name and page title --> <br/> <stackpanel X: Name = "titlepanel" grid. row = "0" margin = ","> <br/> <textblock X: name = "applicationtitle" text = "my application" style = "{staticresource phonetextnormalstyle}"/> <br/> <textblock X: name = "pagetitle" text = "Search" margin = "9,-7, 0, 0 "style =" {staticresource phonetexttitle1style} "/> <br/> </stackpanel> </P> <p> <! -- Contentpanel-place other content here --> <br/> <grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <br/> <textbox Height = "72" horizontalalignment = "Left" margin = "12, 86, 460 "name =" txtkey "verticalignment =" TOP "width =" "/> <br/> <button content =" Search "Height =" 72 "horizontalalignment =" left" margin = ", 86, 160 "name =" button1 "verticalignment =" TOP "width =" "Click =" button#click "/> <br/> </GRID> </P> <p> </phone: phoneapplicationpage> <br/>

Using system; <br/> using system. collections. generic; <br/> using system. LINQ; <br/> using system. net; <br/> using system. windows; <br/> using system. windows. controls; <br/> using system. windows. documents; <br/> using system. windows. input; <br/> using system. windows. media; <br/> using system. windows. media. animation; <br/> using system. windows. shapes; <br/> using Microsoft. phone. controls; <br/> using Microsoft. phone. tasks; </P> <p> namespace sampleapp <br/>{< br/> Public partial class page1: phoneapplicationpage <br/>{< br/> Public page1 () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void button#click (Object sender, routedeventargs E) <br/>{< br/> searchtask searcher = new searchtask (); <br/> searcher. searchquery = txtkey. text; <br/> searcher. show (); <br/>}< br/>}

 

 

 

 

At the beginning of the next section, we will discuss independent storage.

There is also a suggestion that the blog editor has a problem. Every time this happens, after the draft is automatically saved for the first time, it will not be saved, and the text in the editor cannot be selected. The page must be refreshed when you click the post button.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.