-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
586 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.brookmg.exorecord | ||
|
||
import android.app.Application | ||
import dev.brookmg.exorecord.lib.ExoRecord | ||
|
||
class App : Application() { | ||
|
||
companion object { | ||
lateinit var instance: App | ||
val exoRecordInstance: ExoRecord by lazy { ExoRecord(instance) } | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
instance = this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,108 @@ | ||
package dev.brookmg.exorecord | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.content.Context | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Button | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.exoplayer2.DefaultRenderersFactory | ||
import com.google.android.exoplayer2.MediaItem | ||
import com.google.android.exoplayer2.SimpleExoPlayer | ||
import com.google.android.exoplayer2.audio.* | ||
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory | ||
import com.google.android.exoplayer2.source.MediaSource | ||
import com.google.android.exoplayer2.source.ProgressiveMediaSource | ||
import com.google.android.exoplayer2.source.hls.HlsExtractorFactory | ||
import com.google.android.exoplayer2.source.hls.HlsMediaSource | ||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection | ||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector | ||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter | ||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory | ||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource | ||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
const val FORMAT_MP3 = "mp3" | ||
const val FORMAT_MP4 = "mp4" | ||
const val FORMAT_M3U = "m3u" | ||
const val FORMAT_M3U8 = "m3u8" | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
val streamUrl = "https://stream.live.vc.bbcmedia.co.uk/bbc_radio_one?s=1619514803&e=1619529203&h=f378f4ca18759ebfa5fd1d674c794cfc" | ||
|
||
val mainMediaSource: MediaSource | ||
val uri = Uri.parse(streamUrl) | ||
val lastPath = uri.lastPathSegment | ||
|
||
val bandwidthMeter = DefaultBandwidthMeter.Builder(applicationContext).build() | ||
val trackSelectionFactory = AdaptiveTrackSelection.Factory() | ||
val httpDataSourceFactory = DefaultHttpDataSourceFactory( | ||
"-- Audio Test --", | ||
bandwidthMeter, | ||
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, | ||
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, | ||
true | ||
) | ||
|
||
val dataSourceFactory = DefaultDataSourceFactory(this, bandwidthMeter, httpDataSourceFactory) | ||
|
||
if (lastPath == null || lastPath.isEmpty()) return | ||
mainMediaSource = if (lastPath.contains(FORMAT_M3U8) || | ||
lastPath.contains(FORMAT_M3U)) { | ||
HlsMediaSource.Factory(dataSourceFactory) | ||
.setAllowChunklessPreparation(true) | ||
.setExtractorFactory(HlsExtractorFactory.DEFAULT) | ||
.createMediaSource(MediaItem.fromUri(uri)) | ||
} else { | ||
ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory()).createMediaSource( | ||
MediaItem.fromUri(uri) | ||
) | ||
} | ||
|
||
val renderersFactory = object : DefaultRenderersFactory(this) { | ||
override fun buildAudioSink( | ||
context: Context, enableFloatOutput: Boolean, | ||
enableAudioTrackPlaybackParams: Boolean, enableOffload: Boolean | ||
): AudioSink { | ||
return DefaultAudioSink( | ||
AudioCapabilities.DEFAULT_AUDIO_CAPABILITIES, | ||
DefaultAudioSink.DefaultAudioProcessorChain(App.exoRecordInstance.exoRecordProcessor), | ||
enableFloatOutput, enableAudioTrackPlaybackParams, enableOffload | ||
) | ||
} | ||
} | ||
|
||
val trackSelector = DefaultTrackSelector(applicationContext, trackSelectionFactory) | ||
val exoPlayer = SimpleExoPlayer.Builder(applicationContext, renderersFactory) | ||
.setTrackSelector(trackSelector) | ||
.setBandwidthMeter(bandwidthMeter) | ||
.build() | ||
|
||
exoPlayer.setMediaSource(mainMediaSource) | ||
exoPlayer.prepare() | ||
|
||
findViewById<Button>(R.id.button).setOnClickListener { exoPlayer.playWhenReady = true } | ||
findViewById<Button>(R.id.button2).setOnClickListener { exoPlayer.stop() } | ||
|
||
findViewById<Button>(R.id.button_rec).setOnClickListener { | ||
CoroutineScope(Dispatchers.Main).launch { | ||
App.exoRecordInstance.startRecording() | ||
} | ||
} | ||
|
||
findViewById<Button>(R.id.button_rec_stop).setOnClickListener { | ||
CoroutineScope(Dispatchers.Main).launch { | ||
Log.e("CONVERSION", App.exoRecordInstance.stopRecording(true).toString()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,71 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:id="@+id/tview" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
android:text="@string/exorecord_nothing" | ||
android:padding="16dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<Button | ||
android:id="@+id/button" | ||
android:layout_marginTop="16dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintTop_toBottomOf="@+id/tview" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toStartOf="@+id/button2" | ||
android:text="@string/start" | ||
tools:layout_editor_absoluteX="203dp" | ||
tools:layout_editor_absoluteY="412dp" /> | ||
|
||
<Button | ||
android:id="@+id/button2" | ||
android:layout_marginTop="16dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintTop_toBottomOf="@+id/tview" | ||
app:layout_constraintStart_toEndOf="@+id/button" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:text="@string/stop" | ||
tools:layout_editor_absoluteX="169dp" | ||
tools:layout_editor_absoluteY="509dp" /> | ||
|
||
<Button | ||
android:id="@+id/button_rec" | ||
android:layout_marginTop="16dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:backgroundTint="#a00000" | ||
app:layout_constraintTop_toBottomOf="@+id/button" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toStartOf="@+id/button2" | ||
android:text="@string/start_recording" | ||
tools:layout_editor_absoluteX="203dp" | ||
tools:layout_editor_absoluteY="412dp" /> | ||
|
||
<Button | ||
android:id="@+id/button_rec_stop" | ||
android:layout_marginTop="16dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:backgroundTint="#a00000" | ||
app:layout_constraintTop_toBottomOf="@+id/button" | ||
app:layout_constraintStart_toEndOf="@+id/button" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:text="@string/stop_recording" | ||
tools:layout_editor_absoluteX="169dp" | ||
tools:layout_editor_absoluteY="509dp" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<resources> | ||
<string name="app_name">ExoRecord</string> | ||
<string name="exorecord_nothing">ExoRecord --- --- --- NOTHING!</string> | ||
<string name="start">Start</string> | ||
<string name="stop">Stop</string> | ||
<string name="start_recording">Start Recording</string> | ||
<string name="stop_recording">Stop Recording</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dev.brookmg.exoplayer"> | ||
package="dev.brookmg.exorecord.lib"> | ||
|
||
</manifest> |
16 changes: 16 additions & 0 deletions
16
exorecord/src/main/java/dev/brookmg/exorecord/lib/ExoRecord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.brookmg.exorecord.lib | ||
|
||
import android.app.Application | ||
|
||
/** | ||
* It's wise to pass the application context here | ||
*/ | ||
class ExoRecord(private val application: Application) : IExoRecord{ | ||
|
||
val exoRecordProcessor: ExoRecordProcessor by lazy { ExoRecordProcessor(applicationContext = application) } | ||
|
||
override suspend fun startRecording() = exoRecordProcessor.startRecording() | ||
|
||
override suspend fun stopRecording(saveAsAAC: Boolean): IExoRecord.Record = exoRecordProcessor.stopRecording(saveAsAAC) | ||
|
||
} |
Oops, something went wrong.