[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi/command ControlStreamFileCom
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-08-28 13:33:21
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17778/src/java/net/sf/asterisk/fastagi/command Added Files: ControlStreamFileCommand.java Log Message: Added ControlStreamFileCommand (AJ-3) --- NEW FILE: ControlStreamFileCommand.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi.command; /** * Plays the given file, allowing playback to be interrupted by the given * digits, if any, and allows the listner to control the stream.<br> * If offset is provided then the audio will seek to sample offset before play * starts.<br> * Returns 0 if playback completes without a digit being pressed, or the ASCII * numerical value of the digit if one was pressed, or -1 on error or if the * channel was disconnected. <br> * Remember, the file extension must not be included in the filename.<br> * Available since Asterisk 1.2 * * @author srt * @version $Id: ControlStreamFileCommand.java,v 1.1 2005/08/28 13:33:09 srt Exp $ * @since 0.2 */ public class ControlStreamFileCommand extends AGICommand { /** * Serial version identifier. */ private static final long serialVersionUID = 3978141041352128820L; /** * The name of the file to stream. */ private String file; /** * When one of these digits is pressed while streaming the command returns. */ private String escapeDigits; /** * The offset samples to skip before streaming. */ private int offset; private String forwardDigit; private String rewindDigit; private String pauseDigit; /** * Creates a new ControlStreamFileCommand, streaming from the beginning. It * uses the default digit "#" for forward and "*" for rewind and does not * support pausing. * * @param file the name of the file to stream, must not include extension. */ public ControlStreamFileCommand(String file) { this.file = file; this.escapeDigits = null; this.offset = -1; } /** * Creates a new ControlStreamFileCommand, streaming from the beginning. It * uses the default digit "#" for forward and "*" for rewind and does not * support pausing. * * @param file the name of the file to stream, must not include extension. * @param escapeDigits contains the digits that allow the user to interrupt * this command. */ public ControlStreamFileCommand(String file, String escapeDigits) { this.file = file; this.escapeDigits = escapeDigits; this.offset = -1; } /** * Creates a new ControlStreamFileCommand, streaming from the given offset. * It uses the default digit "#" for forward and "*" for rewind and does not * support pausing. * * @param file the name of the file to stream, must not include extension. * @param escapeDigits contains the digits that allow the user to interrupt * this command. Maybe <code>null</code> if you don't want the * user to interrupt. * @param offset the offset samples to skip before streaming. */ public ControlStreamFileCommand(String file, String escapeDigits, int offset) { this.file = file; this.escapeDigits = escapeDigits; this.offset = offset; } /** * Creates a new ControlStreamFileCommand, streaming from the given offset. * It uses the default digit "#" for forward and "*" for rewind and does not * support pausing. * * @param file the name of the file to stream, must not include extension. * @param escapeDigits contains the digits that allow the user to interrupt * this command. Maybe <code>null</code> if you don't want the * user to interrupt. * @param offset the offset samples to skip before streaming. * @param forwardDigit * @param rewindDigit * @param pauseDigit */ public ControlStreamFileCommand(String file, String escapeDigits, int offset, String forwardDigit, String rewindDigit, String pauseDigit) { this.file = file; this.escapeDigits = escapeDigits; this.offset = offset; this.forwardDigit = forwardDigit; this.rewindDigit = rewindDigit; this.pauseDigit = pauseDigit; } /** * Returns the name of the file to stream. * * @return the name of the file to stream. */ public String getFile() { return file; } /** * Sets the name of the file to stream. * * @param file the name of the file to stream, must not include extension. */ public void setFile(String file) { this.file = file; } /** * Returns the digits that allow the user to interrupt this command. * * @return the digits that allow the user to interrupt this command. */ public String getEscapeDigits() { return escapeDigits; } /** * Sets the digits that allow the user to interrupt this command. * * @param escapeDigits the digits that allow the user to interrupt this * command or <code>null</code> for none. */ public void setEscapeDigits(String escapeDigits) { this.escapeDigits = escapeDigits; } /** * Returns the offset samples to skip before streaming. * * @return the offset samples to skip before streaming. */ public int getOffset() { return offset; } /** * Sets the offset samples to skip before streaming. * * @param offset the offset samples to skip before streaming. */ public void setOffset(int offset) { this.offset = offset; } /** * Returns the digit for fast forward. * * @return the digit for fast forward. */ public String getForwardDigit() { return forwardDigit; } /** * Returns the digit for rewind. * * @return the digit for rewind. */ public String getRewindDigit() { return rewindDigit; } /** * Retruns the digit for pause and unpause. * * @return the digit for pause and unpause. */ public String getPauseDigit() { return pauseDigit; } /** * Sets the control digits for fast forward and rewind. * * @param forwardDigit the digit for fast forward. * @param rewindDigit the digit for rewind. */ public void setControlDigits(String forwardDigit, String rewindDigit) { this.forwardDigit = forwardDigit; this.rewindDigit = rewindDigit; } /** * Sets the control digits for fast forward, rewind and pause. * * @param forwardDigit the digit for fast forward. * @param rewindDigit the digit for rewind. * @param pauseDigit the digit for pause and unpause. */ public void setControlDigits(String forwardDigit, String rewindDigit, String pauseDigit) { this.forwardDigit = forwardDigit; this.rewindDigit = rewindDigit; this.pauseDigit = pauseDigit; } public String buildCommand() { StringBuffer sb; sb = new StringBuffer("CONTROL STREAM FILE "); sb.append(escapeAndQuote(file)); sb.append(" "); sb.append(escapeAndQuote(escapeDigits)); if (offset >= 0) { sb.append(" "); sb.append(offset); } else if (forwardDigit != null || rewindDigit != null || pauseDigit != null) { sb.append(" 0"); } if (forwardDigit != null || rewindDigit != null || pauseDigit != null) { sb.append(" "); sb.append(forwardDigit); } if (rewindDigit != null || pauseDigit != null) { sb.append(" "); sb.append(rewindDigit); } if (pauseDigit != null) { sb.append(" "); sb.append(pauseDigit); } return sb.toString(); } } |