/**
   * Sets the visible data about the channel of the currently logged in user.
   *
   * @param channel The name of the channel.
   * @param game The name of the game. If the empty string or null then this parameter is ignored.
   * @param title The title of the channel. If the empty string or null then this parameter is
   *     ignored.
   * @return Whether or not the request was made
   */
  public boolean setStreamInfo(String channel, String game, String title) {
    if (!m_LoggedIn) {
      return false;
    }

    if (channel == null || channel == "") {
      channel = m_UserName;
    }

    if (game == null) {
      game = "";
    }

    if (title == null) {
      title = "";
    }

    StreamInfoForSetting info = new StreamInfoForSetting();
    info.streamTitle = title;
    info.gameName = game;

    ErrorCode err = m_Stream.setStreamInfo(m_AuthToken, channel, info);
    checkError(err);

    return ErrorCode.succeeded(err);
  }
  /** Initializes the SDK and the controller. */
  public boolean initializeTwitch() {
    if (m_SdkInitialized) {
      return false;
    }

    String dllPath = m_DllPath;
    if (dllPath == "") {
      dllPath = "./";
    }

    m_Stream.setStreamCallbacks(this);

    ErrorCode err = m_Stream.initialize(m_ClientId, VideoEncoder.TTV_VID_ENC_DEFAULT, dllPath);
    if (!checkError(err)) {
      m_Stream.setStreamCallbacks(null);
      return false;
    }

    err = m_Stream.setTraceLevel(MessageLevel.TTV_ML_ERROR);
    if (!checkError(err)) {
      m_Stream.setStreamCallbacks(null);
      return false;
    }

    if (ErrorCode.succeeded(err)) {
      m_SdkInitialized = true;
      setBroadcastState(BroadcastState.Initialized);
      return true;
    }

    return false;
  }
  public ErrorCode submitFrame(FrameBuffer bgraFrame) {
    if (this.getIsPaused()) {
      resumeBroadcasting();
    } else if (!this.getIsBroadcasting()) {
      return ErrorCode.TTV_EC_STREAM_NOT_STARTED;
    }

    ErrorCode ret = m_Stream.submitVideoFrame(bgraFrame);

    // if there is a problem when submitting a frame let the client know
    if (ret != ErrorCode.TTV_EC_SUCCESS) {
      String err = ErrorCode.getString(ret);
      if (ErrorCode.succeeded(ret)) {
        reportWarning(String.format("Warning in SubmitTexturePointer: %s\n", err));
      } else {
        reportError(String.format("Error in SubmitTexturePointer: %s\n", err));

        // errors are not recoverable
        stopBroadcasting();
      }

      if (m_Listener != null) {
        m_Listener.onframeSubmissionIssue(ret);
      }
    }

    return ret;
  }
  public void stopCallback(ErrorCode ret) {
    if (ErrorCode.succeeded(ret)) {
      m_VideoParams = null;
      m_AudioParams = null;

      cleanupBuffers();

      try {
        if (m_Listener != null) {
          m_Listener.onBroadcastStopped();
        }
      } catch (Exception x) {
        reportError(x.toString());
      }

      if (m_LoggedIn) {
        setBroadcastState(BroadcastState.ReadyToBroadcast);
      } else {
        setBroadcastState(BroadcastState.Initialized);
      }
    } else {
      // there's not really a good state to go into here
      setBroadcastState(BroadcastState.ReadyToBroadcast);

      String err = ErrorCode.getString(ret);
      reportError(String.format("stopCallback got failure: %s", err));
    }
  }
Example #5
0
 public void onLoginAttemptComplete(ErrorCode result) {
   if (ErrorCode.succeeded(result)) {
     if (enableChat) {
       initChat();
     }
   }
 }
Example #6
0
 public void onGameNameListReceived(ErrorCode result, GameInfo[] list) {
   if (ErrorCode.succeeded(result)) {
     System.out.println("Game names:");
     for (int i = 0; i < list.length; ++i) {
       System.out.println("    " + list[i].name);
     }
   }
 }
  /**
   * Runs a commercial on the channel. Must be broadcasting.
   *
   * @return Whether or not successful
   */
  public boolean runCommercial() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode err = m_Stream.runCommercial(m_AuthToken);
    checkError(err);

    return ErrorCode.succeeded(err);
  }
  /**
   * Terminates the broadcast.
   *
   * @return Whether or not successfully stopped
   */
  public boolean stopBroadcasting() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode ret = m_Stream.stop(true);
    if (ErrorCode.failed(ret)) {
      String err = ErrorCode.getString(ret);
      reportError(String.format("Error while stopping the broadcast: %s", err));
      return false;
    }

    setBroadcastState(BroadcastState.Stopping);

    return ErrorCode.succeeded(ret);
  }
  public void getStreamInfoCallback(ErrorCode result, StreamInfo streamInfo) {
    if (ErrorCode.succeeded(result)) {
      m_StreamInfo = streamInfo;

      try {
        if (m_Listener != null) {
          m_Listener.onStreamInfoUpdated(streamInfo);
        }
      } catch (Exception x) {
        reportError(x.toString());
      }
    } else {
      // String err = ErrorCode.getString(result);
      // reportWarning(String.Format("StreamInfoDoneCallback got failure: {0}", err));
    }
  }
  /**
   * Pauses the current broadcast and displays the default pause screen.
   *
   * @return Whether or not successfully paused
   */
  public boolean pauseBroadcasting() {
    if (!this.getIsBroadcasting()) {
      return false;
    }

    ErrorCode ret = m_Stream.pauseVideo();
    if (ErrorCode.failed(ret)) {
      // not streaming anymore
      stopBroadcasting();

      String err = ErrorCode.getString(ret);
      reportError(String.format("Error pausing stream: %s\n", err));
    } else {
      setBroadcastState(BroadcastState.Paused);
    }

    return ErrorCode.succeeded(ret);
  }
  public void startCallback(ErrorCode ret) {
    if (ErrorCode.succeeded(ret)) {
      try {
        if (m_Listener != null) {
          m_Listener.onBroadcastStarted();
        }
      } catch (Exception x) {
        reportError(x.toString());
      }

      setBroadcastState(BroadcastState.Broadcasting);
    } else {
      m_VideoParams = null;
      m_AudioParams = null;

      setBroadcastState(BroadcastState.ReadyToBroadcast);

      String err = ErrorCode.getString(ret);
      reportError(String.format("startCallback got failure: %s", err));
    }
  }
  public void loginCallback(ErrorCode result, ChannelInfo channelInfo) {
    if (ErrorCode.succeeded(result)) {
      m_ChannelInfo = channelInfo;
      setBroadcastState(BroadcastState.LoggedIn);
      m_LoggedIn = true;
    } else {
      setBroadcastState(BroadcastState.Initialized);
      m_LoggedIn = false;

      String err = ErrorCode.getString(result);
      reportError(String.format("LoginCallback got failure: %s", err));
    }

    try {
      if (m_Listener != null) {
        m_Listener.onLoginAttemptComplete(result);
      }
    } catch (Exception x) {
      reportError(x.toString());
    }
  }
  public void requestAuthTokenCallback(ErrorCode result, AuthToken authToken) {
    if (ErrorCode.succeeded(result)) {
      // Now that the user is authorized the information can be requested about which server to
      // stream to
      m_AuthToken = authToken;
      setBroadcastState(BroadcastState.Authenticated);
    } else {
      m_AuthToken.data = "";
      setBroadcastState(BroadcastState.Initialized);

      String err = ErrorCode.getString(result);
      reportError(String.format("RequestAuthTokenDoneCallback got failure: %s", err));
    }

    try {
      if (m_Listener != null) {
        m_Listener.onAuthTokenRequestComplete(result, authToken);
      }
    } catch (Exception x) {
      reportError(x.toString());
    }
  }
  /**
   * Asynchronously request an authentication key based on the provided username and password. When
   * the request completes onAuthTokenRequestComplete will be fired. This does not need to be called
   * every time the user wishes to stream. A valid auth token can be saved locally between sessions
   * and restored by calling SetAuthToken. If a request for a new auth token is made it will
   * invalidate the previous valid auth token. If successful, this will proceed to log the user in
   * and will fire OnLoginAttemptComplete with the result.
   *
   * @param username The account username
   * @param password The account password
   * @return Whether or not the request was made
   */
  public boolean requestAuthToken(String username, String password) {
    if (getIsIngestTesting() || !m_SdkInitialized) {
      return false;
    }

    logout();

    m_UserName = username;

    AuthParams authParams = new AuthParams();
    authParams.userName = username;
    authParams.password = password;
    authParams.clientSecret = m_ClientSecret;

    ErrorCode err = m_Stream.requestAuthToken(authParams);
    checkError(err);

    if (ErrorCode.succeeded(err)) {
      setBroadcastState(BroadcastState.Authenticating);
      return true;
    }

    return false;
  }
  public void getIngestServersCallback(ErrorCode result, IngestList ingestList) {
    if (ErrorCode.succeeded(result)) {
      m_IngestList = ingestList;

      // assume we're going to use the default ingest server unless overridden by the client
      m_IngestServer = m_IngestList.getDefaultServer();

      setBroadcastState(BroadcastState.ReceivedIngestServers);

      try {
        if (m_Listener != null) {
          m_Listener.onIngestListReceived(ingestList);
        }
      } catch (Exception x) {
        reportError(x.toString());
      }
    } else {
      String err = ErrorCode.getString(result);
      reportError(String.format("IngestListCallback got failure: %s", err));

      // try again
      setBroadcastState(BroadcastState.LoggingIn);
    }
  }