<commit_before>package de.danoeh.antennapod.core.service.playback;

import android.content.Context;
import android.net.Uri;
import android.view.SurfaceHolder;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SeekParameters;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import de.danoeh.antennapod.core.util.playback.IPlayer;
import org.antennapod.audio.MediaPlayer;

import java.io.File;
import java.io.IOException;

/**
 * @author <NAME>
 * @version 1.0
 */
public class ExoPlayer implements IPlayer {
    private final Context mContext;
    private SimpleExoPlayer mExoPlayer;
    private MediaSource mediaSource;
    private MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener;

    public ExoPlayer(Context context) {
        mContext = context;
        mExoPlayer = createPlayer();
    }

    private SimpleExoPlayer createPlayer() {
        SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(
                mContext, new DefaultTrackSelector(), new DefaultLoadControl());
        p.setSeekParameters(SeekParameters.PREVIOUS_SYNC);
        return p;
    }

    @Override
    public boolean canSetPitch() {
        return true;
    }

    @Override
    public boolean canSetSpeed() {
        return true;
    }

    @Override
    public boolean canDownmix() {
        return false;
    }

    @Override
    public float getCurrentPitchStepsAdjustment() {
        return 0;
    }

    @Override
    public int getCurrentPosition() {
        return (int) mExoPlayer.getCurrentPosition();
    }

    @Override
    public float getCurrentSpeedMultiplier() {
        return 0;
    }

    @Override
    public int getDuration() {
        return (int) mExoPlayer.getDuration();
    }

    @Override
    public float getMaxSpeedMultiplier() {
        return 0;
    }

    @Override
    public float getMinSpeedMultiplier() {
        return 0;
    }

    @Override
    public boolean isLooping() {
        return mExoPlayer.getRepeatMode() == Player.REPEAT_MODE_ONE;
    }

    @Override
    public boolean isPlaying() {
        return mExoPlayer.getPlayWhenReady();
    }

    @Override
    public void pause() {
        mExoPlayer.setPlayWhenReady(false);
    }

    @Override
    public void prepare() throws IllegalStateException {
        mExoPlayer.prepare(mediaSource);
    }

    @Override
    public void prepareAsync() {
        mExoPlayer.prepare(mediaSource);
    }

    @Override
    public void release() {
        if (mExoPlayer != null) {
            mExoPlayer.release();
        }
    }

    @Override
    public void reset() {
        mExoPlayer.release();
        mExoPlayer = createPlayer();
    }

    @Override
    public void seekTo(int i) throws IllegalStateException {
        mExoPlayer.seekTo(i);
        audioSeekCompleteListener.onSeekComplete(null);
    }

    @Override
    public void setAudioStreamType(int i) {
        mExoPlayer.setAudioStreamType(i);
    }

    @Override
    public void setScreenOnWhilePlaying(boolean screenOn) {

    }

    @Override
    public void setDataSource(String s) throws IllegalArgumentException, IllegalStateException, IOException {
        DataSource.Factory dataSourceFactory =
                new DefaultDataSourceFactory(
                        mContext, Util.getUserAgent(mContext, "uamp"), null);
        // Produces Extractor instances for parsing the media data.
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        mediaSource = new ExtractorMediaSource(
                Uri.fromFile(new File(s)), dataSourceFactory, extractorsFactory, null, null);
    }

    @Override<commit_msg>Added streaming support<commit_after>package de.danoeh.antennapod.core.service.playback;

import android.content.Context;
import android.net.Uri;
import android.view.SurfaceHolder;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SeekParameters;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import de.danoeh.antennapod.core.util.playback.IPlayer;
import org.antennapod.audio.MediaPlayer;

import java.io.File;
import java.io.IOException;

/**
 * @author <NAME>
 * @version 1.0
 */
public class ExoPlayer implements IPlayer {
    private final Context mContext;
    private SimpleExoPlayer mExoPlayer;
    private MediaSource mediaSource;
    private MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener;

    public ExoPlayer(Context context) {
        mContext = context;
        mExoPlayer = createPlayer();
    }

    private SimpleExoPlayer createPlayer() {
        SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(
                mContext, new DefaultTrackSelector(), new DefaultLoadControl());
        p.setSeekParameters(SeekParameters.PREVIOUS_SYNC);
        return p;
    }

    @Override
    public boolean canSetPitch() {
        return true;
    }

    @Override
    public boolean canSetSpeed() {
        return true;
    }

    @Override
    public boolean canDownmix() {
        return false;
    }

    @Override
    public float getCurrentPitchStepsAdjustment() {
        return 0;
    }

    @Override
    public int getCurrentPosition() {
        return (int) mExoPlayer.getCurrentPosition();
    }

    @Override
    public float getCurrentSpeedMultiplier() {
        return 0;
    }

    @Override
    public int getDuration() {
        return (int) mExoPlayer.getDuration();
    }

    @Override
    public float getMaxSpeedMultiplier() {
        return 0;
    }

    @Override
    public float getMinSpeedMultiplier() {
        return 0;
    }

    @Override
    public boolean isLooping() {
        return mExoPlayer.getRepeatMode() == Player.REPEAT_MODE_ONE;
    }

    @Override
    public boolean isPlaying() {
        return mExoPlayer.getPlayWhenReady();
    }

    @Override
    public void pause() {
        mExoPlayer.setPlayWhenReady(false);
    }

    @Override
    public void prepare() throws IllegalStateException {
        mExoPlayer.prepare(mediaSource);
    }

    @Override
    public void prepareAsync() {
        mExoPlayer.prepare(mediaSource);
    }

    @Override
    public void release() {
        if (mExoPlayer != null) {
            mExoPlayer.release();
        }
    }

    @Override
    public void reset() {
        mExoPlayer.release();
        mExoPlayer = createPlayer();
    }

    @Override
    public void seekTo(int i) throws IllegalStateException {
        mExoPlayer.seekTo(i);
        audioSeekCompleteListener.onSeekComplete(null);
    }

    @Override
    public void setAudioStreamType(int i) {
        mExoPlayer.setAudioStreamType(i);
    }

    @Override
    public void setScreenOnWhilePlaying(boolean screenOn) {

    }

    @Override
    public void setDataSource(String s) throws IllegalArgumentException, IllegalStateException, IOException {
        DataSource.Factory dataSourceFactory =
                new DefaultDataSourceFactory(
                        mContext, Util.getUserAgent(mContext, "uamp"), null);
        // Produces Extractor instances for parsing the media data.
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        mediaSource = new ExtractorMediaSource(
                Uri.parse(s), dataSourceFactory, extractorsFactory, null, null);
    }

    @Override
{'fraction_non_alphanumeric': 0.08530805687203792, 'fraction_numerical': 0.004623742919893654, 'mean_word_length': 3.112167300380228, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438999', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2448, 'n_words': 494}