Пример #1
0
void WMediaPlayer::seek(double time)
{
  if (status_.seekPercent != 0) {
    double pct = time / (status_.seekPercent * status_.duration / 100);
    pct = std::min(1.0, pct);

    playerDo("playHead", boost::lexical_cast<std::string>(pct * 100));
  }
}
Пример #2
0
void WMediaPlayer::play()
{
  if (isRendered()) {
    /*
     * play is being delayed so that other changes (e.g. addSource() are
     * reflected first, see #2819
     */
    doJavaScript("setTimeout(function(){" + jsPlayerRef() 
		 + ".jPlayer('play'); }, 0);");
  } else
    playerDo("play");
}
Пример #3
0
void WMediaPlayer::setVideoSize(int width, int height)
{
  if (width != videoWidth_ || height != videoHeight_) {
    videoWidth_ = width;
    videoHeight_ = height;

    setWidth(videoWidth_);

    if (isRendered()) {
      WStringStream ss;

      ss << "'size', {"
	 <<   "width: \"" << videoWidth_ << "px\","
	 <<   "height: \"" << videoHeight_ << "px\","
	 <<   "cssClass: \"jp-video-" << videoHeight_ << "p\""
	 << "}";

      playerDo("option", ss.str());
    }
  }
}
Пример #4
0
void WMediaPlayer::render(WFlags<RenderFlag> flags)
{
  // XXX subtitles, chapters, stream ?
  static const char *mediaNames[] = {
    "poster",
    "mp3", "m4a", "oga", "wav", "webma", "fla",
    "m4v", "ogv", "webmv", "flv"
  };

  WApplication *app = WApplication::instance();

  if (mediaUpdated_) {
    WStringStream ss;

    ss << '{';

    bool first = true;
    for (unsigned i = 0; i < media_.size(); ++i) {
      if (media_[i].link.isNull())
	continue;

      if (!first)
	ss << ',';

      std::string url = app->resolveRelativeUrl(media_[i].link.url());

      ss << const_cast<char *>(mediaNames[media_[i].encoding]) << ": "
	 << WWebWidget::jsStringLiteral(url);

      first = false;
    }

    ss << '}';

    if (!(flags & RenderFull))
      playerDo("setMedia", ss.str());
    else {
      initialJs_ = ".jPlayer('setMedia', " + ss.str() + ')' + initialJs_;
    }

    mediaUpdated_ = false;
  }

  if (flags & RenderFull) {
    if (gui_ == this)
      createDefaultGui();

    WStringStream ss;

    ss << jsPlayerRef() << ".jPlayer({"
       << "ready: function () {";

    if (!initialJs_.empty())
      ss << "$(this)" << initialJs_ << ';';

    initialJs_.clear();

    ss << "},"
       << "swfPath: \"" << WApplication::resourcesUrl() << "jPlayer\","
       << "supplied: \"";

    bool first = true;
    for (unsigned i = 0; i < media_.size(); ++i) {
      if (media_[i].encoding != PosterImage) {
	if (!first)
	  ss << ',';
	ss << const_cast<char *>(mediaNames[media_[i].encoding]);
	first = false;
      }
    }

    ss << "\",";

    if (mediaType_ == Video) {
      ss << "size: {"
	 <<   "width: \"" << videoWidth_ << "px\","
	 <<   "height: \"" << videoHeight_ << "px\","
	 <<   "cssClass: \"jp-video-" << videoHeight_ << "p\""
	 << "},";
    }

    ss << "cssSelectorAncestor: " << (gui_ ? "'#" + id() + '\'' : "''")
       << ", cssSelector: {";

    const char *controlSelectors[] = 
      { "videoPlay", "play", "pause", "stop", "volumeMute", "volumeUnmute",
	"volumeMax",
	"fullScreen", "restoreScreen", "repeat", "repeatOff" };

    first = true;
    for (unsigned i = VideoPlay; i < RepeatOff; ++i) {
      if (control_[i]) {
	if (!first)
	  ss << ", ";

	ss << const_cast<char *>(controlSelectors[i]) << ":\"#" 
	   << control_[i]->id() << "\"";

	first = false;
      }
    }

    const char *displaySelectors[] = 
      { "currentTime", "duration" };

    for (unsigned i = CurrentTime; i < Duration; ++i) {
      if (control_[i]) {
	if (!first)
	  ss << ", ";

	ss << const_cast<char *>(displaySelectors[i]) << ":\"#"
	   << display_[i]->id() << "\"";

	first = false;
      }
    }

    if (progressBar_[Time]) {
      if (!first)
	ss << ", ";

      ss << "seekBar:\"#" << progressBar_[Time]->id() << "\", "
	 << "playBar:\"#bar" << progressBar_[Time]->id() << "\"";

      first = false;
    }

    if (progressBar_[Volume]) {
      if (!first)
	ss << ", ";

      ss << "volumeBar:\"#" << progressBar_[Volume]->id() << "\", "
	 << "volumeBarValue:\"#bar" << progressBar_[Volume]->id() << "\"";

      first = false;
    }

    ss << '}'
       << "});";

    ss << "new " WT_CLASS ".WMediaPlayer("
       << app->javaScriptClass() << ',' << jsRef() << ");";

    doJavaScript(ss.str());

    boundSignals_ = 0;
  }

  if (boundSignals_ < signals_.size()) {
    WStringStream ss;
    ss << jsPlayerRef();
    for (unsigned i = boundSignals_; i < signals_.size(); ++i)
      ss << ".bind('" << signals_[i]->name() << "', function(o, e) { "
	 << signals_[i]->createCall() << "})";
    ss << ';';

    doJavaScript(ss.str());
    boundSignals_ = signals_.size();
  }

  WCompositeWidget::render(flags);
}
Пример #5
0
void WMediaPlayer::stop()
{
  playerDo("stop");
}
Пример #6
0
void WMediaPlayer::mute(bool mute)
{
  playerDo(mute ? "mute" : "unmute");
}
Пример #7
0
void WMediaPlayer::setVolume(double volume)
{
  status_.volume = volume;
  playerDo("volume", boost::lexical_cast<std::string>(volume));
}
Пример #8
0
void WMediaPlayer::pause()
{
  playerDo("pause");
}
Пример #9
0
void WMediaPlayer::play()
{
  playerDo("play");
}