当前位置: 首页>>代码示例>>Java>>正文


Java AudioFrame类代码示例

本文整理汇总了Java中com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame的典型用法代码示例。如果您正苦于以下问题:Java AudioFrame类的具体用法?Java AudioFrame怎么用?Java AudioFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AudioFrame类属于com.sedmelluq.discord.lavaplayer.track.playback包,在下文中一共展示了AudioFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
@Override
public TrackFrameDataMessage decode(DataInput in, int version) throws IOException {
  long executorId = in.readLong();
  int frameCount = in.readInt();

  List<AudioFrame> frames = new ArrayList<>(frameCount);

  for (int i = 0; i < frameCount; i++) {
    long timecode = in.readLong();
    byte[] data = new byte[in.readInt()];
    in.readFully(data);

    frames.add(new AudioFrame(timecode, data, in.readInt(), null));
  }

  return new TrackFrameDataMessage(executorId, frames, in.readBoolean(), in.readLong());
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:18,代码来源:TrackFrameDataCodec.java

示例2: handleTrackFrameData

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private void handleTrackFrameData(TrackFrameDataMessage message) throws Exception {
  RemoteAudioTrackExecutor executor = playingTracks.get(message.executorId);

  if (executor != null) {
    if (message.seekedPosition >= 0) {
      executor.clearSeek(message.seekedPosition);
    }

    AudioFrameBuffer buffer = executor.getAudioBuffer();
    executor.receivedData();

    AudioDataFormat format = executor.getConfiguration().getOutputFormat();

    for (AudioFrame frame : message.frames) {
      buffer.consume(new AudioFrame(frame.timecode, frame.data, frame.volume, format));
    }

    if (message.finished) {
      buffer.setTerminateOnEmpty();
      trackEnded(executor, false);
    }
  }
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:24,代码来源:RemoteNodeProcessor.java

示例3: tick

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private void tick() throws InterruptedException {
    if(getAverageBufferSize() > 100) {
        //Buffers have plenty to go on
        return;
    }

    AudioFrame provided = player.provide();

    if(subscribers.isEmpty()) {
        // ¯\_(ツ)_/¯
        return;
    }

    // Make sure we reconnect if we lose connection
    if(player.getPlayingTrack() == null) {
        log.info("Track was somehow skipped. Trying to reload the stream...");
        player.playTrack(new AudioLoader().loadSync(streamIdentifier));
        log.info("Loaded new track: " + player.getPlayingTrack().getInfo().title);
    }

    ArrayList<Subscriber> toUnsubscribe = new ArrayList<>();

    if(provided != null) {
        subscribers.forEach(sub -> {
            if(sub.size() > 50 * 5) {
                //Do we have 5 seconds of audio? If so let's unsub
                toUnsubscribe.add(sub);
                log.warn("Unsubscribed stream for having an abnormally long buffer");
            } else {
                sub.feed(provided);
            }
        });
    }

    toUnsubscribe.forEach(Subscriber::unsubscribe);
}
 
开发者ID:Frederikam,项目名称:GensokyoBot,代码行数:37,代码来源:StreamCombiner.java

示例4: provideShadowFrame

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private AudioFrame provideShadowFrame() {
  InternalAudioTrack shadow = shadowTrack;
  AudioFrame frame = null;

  if (shadow != null) {
    frame = shadow.provide();

    if (frame != null && frame.isTerminator()) {
      shadowTrack = null;
      frame = null;
    }
  }

  return frame;
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:16,代码来源:AudioPlayer.java

示例5: provide

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
@Override
public AudioFrame provide(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
  AudioFrame frame = provideDirectly(timeout, unit);
  if (outputHook != null) {
    frame = outputHook.outgoingFrame(this, frame);
  }
  return frame;
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:9,代码来源:AudioPlayer.java

示例6: provideDirectly

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
/**
 * Provide an audio frame bypassing hooks.
 * @param timeout Specifies the maximum time to wait for data. Pass 0 for non-blocking mode.
 * @param unit Specifies the time unit of the maximum wait time.
 * @return An audio frame if available, otherwise null
 */
public AudioFrame provideDirectly(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
  InternalAudioTrack track;

  lastRequestTime = System.currentTimeMillis();

  if (timeout == 0 && paused.get()) {
    return null;
  }

  while ((track = activeTrack) != null) {
    AudioFrame frame = timeout > 0 ? track.provide(timeout, unit) : track.provide();

    if (frame != null) {
      lastReceiveTime = System.nanoTime();
      shadowTrack = null;

      if (frame.isTerminator()) {
        handleTerminator(track);
        continue;
      }
    } else if (timeout == 0) {
      checkStuck(track);

      frame = provideShadowFrame();
    }

    return frame;
  }

  return null;
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:38,代码来源:AudioPlayer.java

示例7: attemptRetrieveFrame

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private void attemptRetrieveFrame() throws TimeoutException, InterruptedException {
  AudioFrame frame = player.provide(timeout, TimeUnit.MILLISECONDS);

  if (frame != null) {
    if (!format.equals(frame.format)) {
      throw new IllegalStateException("Frame read from the player uses a different format than expected.");
    }

    addFrame(frame.data);
  } else if (!provideSilence) {
    Thread.sleep(10);
  }
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:14,代码来源:AudioPlayerInputStream.java

示例8: encode

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
@Override
public void encode(DataOutput out, TrackFrameDataMessage message) throws IOException {
  out.writeLong(message.executorId);
  out.writeInt(message.frames.size());

  for (AudioFrame frame : message.frames) {
    out.writeLong(frame.timecode);
    out.writeInt(frame.data.length);
    out.write(frame.data);
    out.writeInt(frame.volume);
  }

  out.writeBoolean(message.finished);
  out.writeLong(message.seekedPosition);
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:16,代码来源:TrackFrameDataCodec.java

示例9: TrackFrameDataMessage

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
/**
 * @param executorId The ID for the track executor
 * @param frames Frames provided by the node
 * @param finished If these are the last frames for the track
 * @param seekedPosition The position of the seek that was performed
 */
public TrackFrameDataMessage(long executorId, List<AudioFrame> frames, boolean finished, long seekedPosition) {
  this.executorId = executorId;
  this.frames = frames;
  this.finished = finished;
  this.seekedPosition = seekedPosition;
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:13,代码来源:TrackFrameDataMessage.java

示例10: processProvidedFrame

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private void processProvidedFrame(AudioFrame frame) {
  if (frame != null && !frame.isTerminator()) {
    lastFrameTimecode.set(frame.timecode);

    if (pendingSeek.get() == NO_SEEK && !frameBuffer.hasClearOnInsert()) {
      markerTracker.checkPlaybackTimecode(frame.timecode);
    }
  }
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:10,代码来源:RemoteAudioTrackExecutor.java

示例11: rebuild

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
@Override
public AudioFrame rebuild(AudioFrame frame) {
  if (frame.volume == newVolume) {
    return frame;
  }

  decoder.decode(frame.data, sampleBuffer);

  int targetVolume = newVolume;

  if (++frameIndex < 50) {
    targetVolume = (int) ((newVolume - frame.volume) * (frameIndex / 50.0) + frame.volume);
  }

  // Volume 0 is stored in the frame with volume 100 buffer
  if (targetVolume != 0) {
    volumeProcessor.applyVolume(frame.volume, targetVolume, sampleBuffer);
  }

  byte[] bytes = encoder.encode(sampleBuffer);

  // One frame per 20ms is consumed. To not spike the CPU usage, reencode only once per 5ms. By the time the buffer is
  // fully rebuilt, it is probably near to 3/4 its maximum size.
  try {
    Thread.sleep(5);
  } catch (InterruptedException e) {
    // Keep it interrupted, it will trip on the next interruptible operation
    Thread.currentThread().interrupt();
  }

  return new AudioFrame(frame.timecode, bytes, targetVolume, format);
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:33,代码来源:AudioFrameVolumeChanger.java

示例12: handleTrackDataRequest

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
@MessageHandler
private void handleTrackDataRequest(TrackFrameRequestMessage message, MessageOutput output) {
  List<AudioFrame> frames = new ArrayList<>();
  PlayingTrack track = tracks.get(message.executorId);
  boolean finished = false;

  if (track != null) {
    submitPendingMessages(track, output);

    track.lastFrameRequestTime = System.currentTimeMillis();
    track.volume.set(message.volume);

    if (message.seekPosition >= 0) {
      track.audioTrack.setPosition(message.seekPosition);
    }

    if (message.maximumFrames > 0) {
      track.lastNonZeroFrameRequestTime = track.lastFrameRequestTime;
    }

    finished = consumeFramesFromTrack(frames, track.audioTrack, message.maximumFrames);

    if (finished) {
      log.info("Clearing ended track {} (context {})", track.audioTrack.getIdentifier(), message.executorId);
      tracks.remove(message.executorId);
    }
  }

  output.send(new TrackFrameDataMessage(message.executorId, frames, finished, message.seekPosition));
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:31,代码来源:PlayingTrackManager.java

示例13: consumeFramesFromTrack

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
private boolean consumeFramesFromTrack(List<AudioFrame> frames, InternalAudioTrack audioTrack, int maximumFrames) {
  AudioFrame frame;

  while (frames.size() < maximumFrames && (frame = audioTrack.provide()) != null) {
    if (frame.isTerminator()) {
      return true;
    } else {
      frames.add(frame);
    }
  }

  return false;
}
 
开发者ID:sedmelluq,项目名称:lavaplayer,代码行数:14,代码来源:PlayingTrackManager.java

示例14: feed

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
void feed(AudioFrame frame) {
    buffer.add(frame);
}
 
开发者ID:Frederikam,项目名称:GensokyoBot,代码行数:4,代码来源:Subscriber.java

示例15: provide

import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame; //导入依赖的package包/类
public AudioFrame provide() {
    return buffer.poll();
}
 
开发者ID:Frederikam,项目名称:GensokyoBot,代码行数:4,代码来源:Subscriber.java


注:本文中的com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。