Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsVideo.cpp
Go to the documentation of this file.
1 
2 #include <boost/filesystem/operations.hpp>
3 
4 #include <Wt/WVideo>
5 #include <Wt/WFlashObject>
6 #include <Wt/WMediaPlayer>
7 
8 #include <Logger/WsLogger.h>
9 #include <User/WsUser.h>
10 
11 #include <Main/WsApplication.h>
12 
13 #include "WsVideo.h"
14 
15 using namespace Wt;
16 
17 WsVideo::WsVideo(WContainerWidget* parent)
18  : WContainerWidget(parent)
19 {
20  addStyleClass("WsVideo");
21 }
22 
24 {
25 }
26 
28 {
29  WContainerWidget::load();
30  WsUser* pUser = WsApp->wsUser();
31  if ( !pUser ) return;
32  NodePtr rootNode = pUser->getAccessRoot();
33  if ( !rootNode ) return;
34  NodePtr curNode = rootNode.get()->eatPath(wApp->internalPath());
35  if ( !curNode ) return;
36  std::string m_sDocumentRoot = pUser->getRootPath(); // /var/www/demo_site
37  std::string videoFile = m_sDocumentRoot + wApp->internalPath();
38  WText* pText = new WText(curNode.get()->getDisplayName(true));
39  pText->addStyleClass("WsTitle");
40  addWidget(pText);
41  std::string extension = boost::filesystem::path(videoFile).extension().string();
42  if ( extension == ".ogv" || extension == "mp4" ) {
43  boost::algorithm::replace_first(videoFile, WsApp->docRoot(), "");
44  WVideo* video = new Wt::WVideo(this);
45  video->addSource(Wt::WLink(videoFile));
46  //video->addSource(Wt::WLink(wApp->internalPath());
47  video->resize(640, 360);
48  return;
49  }
50  if ( extension == ".m4v" ) {
51  boost::algorithm::replace_first(videoFile, WsApp->docRoot(), "");
52  WMediaPlayer* player = new WMediaPlayer(Wt::WMediaPlayer::Video, this);
53  player->addSource(Wt::WMediaPlayer::M4V, Wt::WLink(videoFile));
54  //player->addSource(Wt::WMediaPlayer::M4V, Wt::WLink(wApp->internalPath()));
55  player->setVideoSize(640, 360);
56  return;
57  }
58  if ( extension == ".youtube" ) {
59  std::string sUrl;
60  if ( boost::filesystem::exists(videoFile) ) {
61  std::ifstream f(videoFile.c_str());
62  std::getline(f, sUrl); // url without CR
63  }
64  if ( sUrl.size() < 1 ) return;
65  // WFlashObject *flash = new WFlashObject("http://www.youtube.com/embed/k7ZfwYhnSE4", this);
66  WFlashObject* flash = new WFlashObject(sUrl, this);
67  flash->setFlashParameter("allowFullScreen", "true");
68  flash->resize(640, 360);
69  }
70 }
71 
boost::shared_ptr< WsAbstractNode > NodePtr
Interface that provides differents methods for accessing the FsTree as well as other features...
Definition: WsUser.h:33
~WsVideo()
Definition: WsVideo.cpp:23
void load()
Definition: WsVideo.cpp:27
WsVideo(Wt::WContainerWidget *parent=0)
Definition: WsVideo.cpp:17
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
Definition: WsUser.cpp:55
#define WsApp
Define a shortcut to the application instance.
Definition: WsApplication.h:62
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Definition: WsUser.cpp:50
User class.