Play video functions in C + +, playing on slate controls

Source: Internet
Author: User

Create a MediaPlayer material, convert it to a painting brush, and then give Simage, in the Tick update screen, that is, here is the specific code, #pragma once#include "CoreMinimal.h" #include "uobject/ WeakObjectPtr.h "#include" widgets/declarativesyntaxsupport.h "#include" Widgets/scompoundwidget.h "class Uaudiocomponent;class umaterial;class umaterialexpressiontexturesample;class Umediaplayer;class UMediaSoundWave; Class Umediatexture;struct Fslatebrush;enum class emediaevent;/** * */class userinterface_api svideoplay:public SCompou Ndwidget{public:declare_delegate (Fclosevieoplay) Slate_begin_args (svideoplay) {}slate_event (FCloseVieoPlay, Onclosevideoplay) slate_argument (fstring, Videourl) Slate_end_args () Svideoplay (); ~svideoplay ();/** Constructs This Widget with Inargs */void Construct (const farguments& Inargs),/** the material that wraps the video texture for Displa Y in an simage. */umaterial* material;/** The Slate brush that renders the Material. */tsharedptr<fslatebrush> materialbrush;/** The media player whose video texture is shown in this widget. */umediaplayer* MediaPlayer; Umediatexture* defaulttexture; tweakobjectptr<umediatexture> currenttexture;/** The video texture sampler in the wrapper material. */umaterialexpressiontexturesample* texturesampler;virtual void Tick (const fgeometry& allottedgeometry, const Double incurrenttime, const float indeltatime) override;void updatematerial (); Fstring Videourl; Freply Closevideoplay (); Fclosevieoplay Onclosevideoplay;};

Fill out your copyright notice in the Description page of Project Settings. #include "UserInterface.h" #include "svideopl Ay.h "#include" styling/slatebrush.h "#include" widgets/images/simage.h "#include" IMediaOutput.h "#include" IMediaPlayer.h "#include" materials/material.h "#include" materials/materialexpressiontexturesample.h "#include" MediaPlayer.h "#include" MediaTexture.h "#include" Engine.h "#include" SlateOptMacros.h "Svideoplay::svideoplay (): Currenttexture (nullptr), Defaulttexture (nullptr), Material (nullptr), MediaPlayer (nullptr) {//defaultsoundwave = Newobject<umediasoundwave> (Gettransientpackage (), Name_none, Rf_transient | Rf_public);//if (Defaultsoundwave! = nullptr)//{//defaultsoundwave->addtoroot ();//audiocomponent = FAudioDevice: : Createcomponent (Defaultsoundwave);//if (audiocomponent! = nullptr)//{//audiocomponent->setvolumemultiplier ( 1.0f);//audiocomponent->setpitchmultiplier (1.0f);//audiocomponent->ballowspatialization = false;// Audiocomponent->bisuisound = True;//audiocomponent->bautodestroy = False;//audiocomponent->addtoroot ();//}//}}svideoplay::~svideoplay ( ) {if (MediaPlayer! = nullptr) {mediaplayer->onmediaevent (). RemoveAll (this);//remove default sinks from native player//fmediaplayerbase& player = mediaplayer-> Getbaseplayer ();/*if (mediaplayer->getsoundwave () = = nullptr) {player.setaudiosink (nullptr);} *//*if (mediaplayer->getvideotexture () = = nullptr) {player.setvideosink (nullptr);} */}//release default sinks/*if (audiocomponent! = nullptr) {audiocomponent->stop (); Audiocomponent->removefromroot ();} */if (Material! = nullptr) {material->removefromroot ();} /*if (Defaultsoundwave! = nullptr) {defaultsoundwave->removefromroot ();} */if (defaulttexture! = nullptr) {defaulttexture->removefromroot ();}} Begin_slate_function_build_optimizationvoid svideoplay::construct (const farguments& InArgs) {OnCloseVideoPlay = Inargs._onclosevideoplay; Videourl = Inargs._videourl; MediaPlayer = loadobject<umediaplayer> (NULL, TEXT ("/game/common/video/mediaplayer.mediaplayer"), NULL, load_none, NULL); Material = newobject<umaterial> (Gettransientpackage (), Name_none, Rf_transient | Rf_public); if (Material! = nullptr) {Texturesampler = newobject<umaterialexpressiontexturesample> (Material); { Texturesampler->samplertype = Samplertype_color;} fexpressionoutput& Output = texturesampler->getoutputs () [0]; fexpressioninput& Input = material->emissivecolor; {input.expression = Texturesampler;input. Mask = Output.mask;input. Maskr = Output.maskr;input. MASKG = Output.maskg;input. MASKB = Output.maskb;input. Maska = Output.maska;} Material->expressions.add (Texturesampler); Material->materialdomain = ematerialdomain::md_ui; Material->addtoroot ();} Create Slate Brushmaterialbrush = makeshareable (New Fslatebrush ()); {Materialbrush->setresourceobject (Material);} Updatematerial (); Childslot[snew (SBox). Widthoverride (1000). Heightoverride (1000). HAlign (Halign_center). valign (Valign_center) [Snew (SVerticalbox) +sverticalbox::slot (). Autoheight () [Snew (Sbutton). ButtonStyle (Fpanelstyle::get (), "Button_alpha"). OnClicked (this, &svideoplay::closevideoplay). HAlign (halign_right). valign (Valign_center). Content () [Snew (Simage). Image (Fpanelstyle::getbrush ("Scheme_close"))]]+sverticalbox::slot () [Snew (Simage). Image (Materialbrush.get ())]]];//bool isplay = Mediaplayer->openurl (TEXT ("Http://127.0.0.1:8080/Marionette_ Rl.mp4 ")); bool Isplay = Mediaplayer->openurl (Videourl);} End_slate_function_build_optimizationvoid Svideoplay::tick (const fgeometry& allottedgeometry, const double Incurrenttime, const float indeltatime) {updatematerial ();//updatesoundwave ();} void Svideoplay::updatematerial () {umediatexture* Texture = Mediaplayer->getvideotexture ();//if (Texture = nullptr )//{////Create default texture if needed//if (defaulttexture = = nullptr)//{//defaulttexture = newobject< Umediatexture> (Gettransientpackage (), Name_none, Rf_transient | Rf_public);//if (defaulttexture! = nullptr)//{Defaulttexture->updateresource ();//defaulttexture->addtoroot ();//}//}////set default texture as output sink if (defaulttexture! = nullptr)//{//mediaplayer->getbaseplayer (). Setvideosink (defaulttexture);//}//texture = defaulttexture;//}//assign new Texture to Materialif (Texture! = currenttexture) {texturesampler->texture = Texture; Material->posteditchange (); Currenttexture = Texture;} Resize Current Textureif (currenttexture! = nullptr) {materialbrush->imagesize.x = currenttexture-> Getsurfacewidth (); Materialbrush->imagesize.y = Currenttexture->getsurfaceheight ();} Else{materialbrush->imagesize = Fvector2d::zerovector;}} Freply Svideoplay::closevideoplay () {if (Onclosevideoplay.isbound ()) {Onclosevideoplay.execute ();} Onclosevideoplay.executeifbound (); return freply::handled ();}

Audio section commented out, if necessary, self-improvement bar.

  

Play video functions in C + +, playing on slate controls

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.