At our scope previewwidget, we can use audio Previewwidget to play our music. This is for some of the music scope, very much. In today's exercise, let's use it to try out our music in our scope.
First we take advantage of the scope we have already done. We can download the scope we have previously done:
Https://github.com/liu-xiao-guo/scopetemplates
In our query.cpp, let's add the following: query.cpp
void Query::p ushresult (sc::searchreplyproxy const& reply, const string renderer, int i) {s
Tringstream SS;
SS << I;
String str = SS.STR (); Auto cat = reply->register_category ("id" + str, "Template" + str, "", Sc::c
Ategoryrenderer (renderer));
Sc::categorisedresult R (CAT);
R.set_uri (Uri.tostdstring ());
R.set_art (Images_[0].tostdstring ());
r["subtitle"] = "subtitle" + str;
R.set_title ("title" + str);
r["Summary"] = "Summary:" + str;
r["Fulldesc"] = "FULLDESC:" + str;
r["mascot"] = Icons_[0].tostdstring ();
r["emblem"] = icons_[1].tostdstring ();
r["background"] = background_.tostdstring ();
r["Overlay-color"] = "#FF0000";
QString likes = QString ("%1%2"). Arg (Qstr (U8 "\u261d"), "100");
QString views = QString ("%1%2"). Arg (Qstr (U8 "\u261f"), "99");
std::string both = Qstr ("%1%2"). Arg (likes,views). tostdstring (); Sc::variantbuiLder Builder;
Builder.add_tuple ({{"Value", Variant (both)}});
Builder.add_tuple ({{"Value", Variant ("")}});
r["attributes"] = Builder.end ();
r["Musicsource"] = "http://qqmp3.djwma.com/mp3/magic sound God according to the need for Sihuo the saw pulled the eardrum will be broken." MP3 ";
if (!reply->push (r)) return; }
The "Musicsource" above is our newly added item. We have to point out that "Musicsource" is not an item in our standard template, so how do we use it in our preview?
Preview.cpp
void Preview::run (SC::P reviewreplyproxy const& Reply) {//support three different column layouts Sc::columnla
Yout Layout1col (1), Layout2col (2), Layout3col (3); We define 3 different layouts, that'll be a used depending on the//device.
The shell (view) is decide which layout fits best.
If, for instance, we is executing in a tablet probably the view would use//2 or more columns.
Column layout definitions is optional.
However, we recommend that scopes define layouts for the best visual appearance.
Single Column Layout layout1col.add_column ({"Image", "header", "Summary", "tracks"});
Both column layout layout2col.add_column ({"image"});
Layout2col.add_column ({"Header", "Summary", "tracks"});
Three Cokumn layout layout3col.add_column ({"image"});
Layout3col.add_column ({"Header", "Summary", "tracks"});
Layout3col.add_column ({});
Register the layouts we just created Reply->register_layout ({layout1col, Layout2col, layout3col});
Define the header section SC::P reviewwidget Header ("header", "header");
It has title and a subtitle properties header.add_attribute_mapping ("title", "title");
Header.add_attribute_mapping ("subtitle", "subtitle");
Define the Image section SC::P reviewwidget image ("image", "image");
Mapped to the result's art property image.add_attribute_mapping ("source", "art");
Define the Summary section SC::P reviewwidget Description ("Summary", "text"); It has a Text property, mapped to the result ' s Description property description.add_attribute_mapping ("text", "desc
Ription ");
Result result = Previewquerybase::result ();
Previewwidget Listen ("tracks", "Audio");
{Variantbuilder Builder; Builder.add_tuple ({{"title", Variant ("This is the song title")}, {"Source", Variant (result["MusiCsource "].get_string (). C_STR ())});
Listen.add_attribute_value ("Tracks", Builder.end ());
} if (result["Musicsource"].get_string (). Length ()! = 0) {qdebug () << "It is not NULL";
Push each of the sections Reply->push ({image, header, description, listen});
} else {//Push each of the sections Reply->push ({image, header, description}); }
}
Here, we can see:
Result result = Previewquerybase::result ();
Previewwidget Listen ("tracks", "Audio");
{
Variantbuilder builder;
Builder.add_tuple ({
{"title", Variant ("This is the song title")},
{"Source", Variant (result["Musicsource"]. Get_string (). C_STR ())}
);
Listen.add_attribute_value ("Tracks", Builder.end ());
}
if (result["Musicsource"].get_string (). Length ()! = 0) {
qdebug () << "It is not NULL";
Push each of the sections
Reply->push ({image, header, description, listen}), or
else {
//push each Of the sections
Reply->push ({image, header, description});
}
We can get result by means of "result ()". We also created a previewwidget called listen. We use him to create the items we need.
To run our scope:
We can click on the button above to play our music to try to listen.
The source code of the whole project is: Https://github.com/liu-xiao-guo/scopetemplates_audio.git