Using Windows MediaElement to play local Video

In the future if any one has this issue here is the code that worked for me:

 const std::string &url = "ms-appx:///temp.mp4";

auto dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
m_panel = cocos2d::GLViewImpl::sharedOpenGLView()->getPanel();

if(dispatcher->GetType() && m_panel->GetType()){
	
dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, url]() {

		auto mediaElement = ref new Windows::UI::Xaml::Controls::MediaElement();
		mediaElement->Width = 200;

		Windows::Foundation::Uri^ uri = ref new Windows::Foundation::Uri("ms-appx:///temp.mp4");
		mediaElement->Source = uri;

		mediaElement->AutoPlay = true;
		mediaElement->IsFullWindow = true;
		mediaElement->Name = "Intro";
		mediaElement->IsMuted = false;
		m_panel.Get()->Children->Append(mediaElement);


		log("play");
	 
	}));
 }

Also add you video to you assets for both Windows and Windows phone.

Hope this helps someone in the future!
:smile:

2 Likes