Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
getting rid of the local exoplayer copy. yay. see: google/ExoPlayer#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
y20k committed Jan 30, 2018
1 parent 59f620c commit fa7f7eb
Show file tree
Hide file tree
Showing 1,174 changed files with 99 additions and 166,054 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle
Expand Up @@ -37,12 +37,11 @@ dependencies {
implementation 'com.android.support:design:' + supportLibraryVersion
implementation 'com.android.support:support-media-compat:' + supportLibraryVersion
implementation 'com.android.support:palette-v7:' + supportLibraryVersion
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
implementation 'com.android.support.constraint:constraint-layout:' + constraintLayoutVersion

implementation project(':exoplayer-library-core')
implementation project(':exoplayer-library-hls')
implementation 'com.google.android.exoplayer:exoplayer-core:' + exoPlayerVersion
implementation 'com.google.android.exoplayer:exoplayer-hls:' + exoPlayerVersion

implementation 'android.arch.lifecycle:extensions:' + archLifecycleVersion
annotationProcessor 'android.arch.lifecycle:compiler:' + archLifecycleVersion

}
23 changes: 10 additions & 13 deletions app/src/main/java/org/y20k/transistor/PlayerService.java
Expand Up @@ -56,8 +56,6 @@
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
Expand Down Expand Up @@ -704,7 +702,6 @@ private void preparePLayer(int connectionType) {
mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mStation.getStreamUri());
} else {
dataSourceFactory = new CustomDefaultHttpDataSourceFactory(mUserAgent, bandwidthMeter, true, playerCallback);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).setContinueLoadingCheckIntervalBytes(32).createMediaSource(mStation.getStreamUri());
}
// prepare player with source.
Expand Down Expand Up @@ -738,12 +735,12 @@ private AudioFocusRequestCompat createFocusRequest() {

// built and return focus request
return new AudioFocusRequestCompat.Builder(AudioManager.AUDIOFOCUS_GAIN)
.setOnAudioFocusChangeListener(mAudioFocusHelper.getListenerForPlayer(this))
.setAudioAttributes(audioAttributes)
.setFocusGain(AudioManager.AUDIOFOCUS_GAIN)
.setWillPauseWhenDucked(false)
.setAcceptsDelayedFocusGain(false) // todo check if this flag can be turned on (true)
.build();
.setOnAudioFocusChangeListener(mAudioFocusHelper.getListenerForPlayer(this))
.setAudioAttributes(audioAttributes)
.setFocusGain(AudioManager.AUDIOFOCUS_GAIN)
.setWillPauseWhenDucked(false)
.setAcceptsDelayedFocusGain(false) // todo check if this flag can be turned on (true)
.build();
}


Expand Down Expand Up @@ -1008,10 +1005,10 @@ protected void onPostExecute(Integer connectionType) {

// set content type
mPlayer.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MUSIC)
.build()
);
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MUSIC)
.build()
);
}

// release init lock
Expand Down
Expand Up @@ -71,10 +71,10 @@ public CustomDefaultHttpDataSourceFactory(String userAgent,


@Override
public DefaultHttpDataSource createDataSource() {
public DataSource createDataSource() {
// toggle Shoutcast extraction
if (enableShoutcast) {
return new IcyDataSource(userAgent, null, playerCallback);
return new IcyDataSource(playerCallback);
} else {
return new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
readTimeoutMillis, allowCrossProtocolRedirects, null);
Expand Down
118 changes: 82 additions & 36 deletions app/src/main/java/org/y20k/transistor/helpers/IcyDataSource.java
Expand Up @@ -10,17 +10,19 @@
* Licensed under the MIT-License
* http://opensource.org/licenses/MIT
*
* Code adapted from
* https://github.com/Ood-Tsen/ExoPlayer/blob/8ccc99bc5c6428760efd9f1780dd90be9386339e/demo/src/main/java/com/google/android/exoplayer/demo/player/IcyDataSource.java
* Code adapted from:
* https://github.com/google/ExoPlayer/issues/466#issuecomment-361420861
* Credit: https://github.com/asheeshs (Thanks!)
*/


package org.y20k.transistor.helpers;


import android.net.Uri;

import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.util.Predicate;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -31,68 +33,112 @@
/**
* IcyDataSource class
*/
public class IcyDataSource extends DefaultHttpDataSource implements TransistorKeys {
public class IcyDataSource implements DataSource, TransistorKeys {

/* Define log tag */
/* Define log tag */
private static final String LOG_TAG = IcyDataSource.class.getSimpleName();


/* Main class variables */
private boolean metadataEnabled = true;
private PlayerCallback playerCallback;
private final PlayerCallback mPlayerCallback;
private HttpURLConnection mConnection;
private InputStream mInputStream;
private boolean mMetadataEnabled = true;



/* Constructor */
public IcyDataSource(String userAgent, Predicate<String> contentTypePredicate, PlayerCallback playerCallback) {
super(userAgent, contentTypePredicate);
this.playerCallback = playerCallback;
public IcyDataSource(final PlayerCallback playerCallback) {
mPlayerCallback = playerCallback;
}


@Override
public long open(DataSpec dataSpec) throws HttpDataSourceException {
return super.open(dataSpec);
public long open(final DataSpec dataSpec) throws IOException {
LogHelper.i(LOG_TAG, "open[" + dataSpec.position + "-" + dataSpec.length);

URL url = new URL(dataSpec.uri.toString());
mConnection = (HttpURLConnection) url.openConnection();
mConnection.setRequestProperty("Icy-Metadata", "1");

try {
mInputStream = getInputStream(mConnection);
} catch (Exception e) {
closeConnectionQuietly();
throw new IOException(e.getMessage());
}

return dataSpec.length;
}

@Override
protected HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
// open a http connection for Icy-Metadata (Shoutcast)
LogHelper.i(LOG_TAG, "makeConnection[" + dataSpec.position + "-" + dataSpec.length);

URL url = new URL(dataSpec.uri.toString());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Icy-Metadata", "1");
return connection;
@Override
public int read(final byte[] buffer, final int offset, final int readLength) throws IOException {
return mInputStream.read(buffer, offset, readLength);
}


@Override
protected InputStream getInputStream(HttpURLConnection conn) throws Exception {
// Get the input stream from the connection. Actually returns the underlying stream or IcyInputStream
String smetaint = conn.getHeaderField( "icy-metaint");
InputStream ret = conn.getInputStream();
public Uri getUri() {
return mConnection == null ? null : Uri.parse(mConnection.getURL().toString());
}

if (!metadataEnabled) {
LogHelper.v(LOG_TAG, "Metadata not enabled");
@Override
public void close() throws IOException {
try {
if (mInputStream != null) {
try {
mInputStream.close();
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
} finally {
mInputStream = null;
closeConnectionQuietly();
}
else if (smetaint != null) {
}


/* Gets input stream from mConnection. Actually returns underlying stream or IcyInputStream. */
protected InputStream getInputStream( HttpURLConnection conn ) throws Exception {
String metaint = conn.getHeaderField( "icy-metaint" );
InputStream inputStream = conn.getInputStream();

if (!mMetadataEnabled) {
LogHelper.i(LOG_TAG, "Metadata not enabled" );
}
else if (metaint != null) {
int period = -1;
try {
period = Integer.parseInt( smetaint);
period = Integer.parseInt( metaint );
}
catch (Exception e) {
LogHelper.e(LOG_TAG, "The icy-metaint '" + smetaint + "' cannot be parsed: '" + e);
LogHelper.e(LOG_TAG, "The icy-metaint '" + metaint + "' cannot be parsed: '" + e );
}

if (period > 0) {
LogHelper.v(LOG_TAG, "The dynamic metainfo is sent every " + period + " bytes");

ret = new IcyInputStream(ret, period, playerCallback, null);
LogHelper.i(LOG_TAG, "The dynamic metainfo is sent every " + period + " bytes" );
inputStream = new IcyInputStream(inputStream, period, mPlayerCallback, null );
}
}
else LogHelper.v(LOG_TAG, "This stream does not provide dynamic metainfo");
else {
LogHelper.i(LOG_TAG, "This stream does not provide dynamic metainfo" );
}

return ret;
return inputStream;
}


/* Closes the current mConnection quietly, if there is one. */
private void closeConnectionQuietly() {
if (mConnection != null) {
try {
mConnection.disconnect();
} catch (Exception e) {
LogHelper.e(LOG_TAG, "Unexpected error while disconnecting. " + e.toString());
}
mConnection = null;
}
}

}
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -32,6 +32,8 @@ allprojects {
buildToolsVersion = '27.0.3'
supportLibraryVersion = '27.0.2'
archLifecycleVersion = '1.0.0'
constraintLayoutVersion = '1.1.0-beta4'
exoPlayerVersion = '2.6.1'
junit_version = "4.12"
}

Expand Down
64 changes: 0 additions & 64 deletions libraries/ExoPlayer-r2.6.1/.gitignore

This file was deleted.

71 changes: 0 additions & 71 deletions libraries/ExoPlayer-r2.6.1/.hgignore

This file was deleted.

0 comments on commit fa7f7eb

Please sign in to comment.