Skip to content

Commit

Permalink
audio added
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshbaid committed Jun 29, 2020
1 parent 44b5baf commit ec174f4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
Expand All @@ -23,6 +24,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.FileProvider;
Expand All @@ -38,11 +40,15 @@
import com.burhanrashid52.photoeditor.tools.EditingToolsAdapter;
import com.burhanrashid52.photoeditor.tools.ToolType;
import com.daasuu.epf.EPlayerView;
import com.daasuu.epf.PlayerScaleType;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
Expand Down Expand Up @@ -88,6 +94,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
private EPlayerView ePlayerView;
private SimpleExoPlayer player;
private PlayerTimer playerTimer;
private SimpleExoPlayer audioMediaPlayer;

@Nullable
@VisibleForTesting
Expand Down Expand Up @@ -133,38 +140,41 @@ protected void onCreate(Bundle savedInstanceState) {
.build(); // build photo editor sdk

mPhotoEditor.setOnPhotoEditorListener(this);



//Set Image Dynamically
// mPhotoEditorView.getSource().setImageResource(R.drawable.color_palette);
}

@Override
protected void onResume()
{
super.onResume();
try{
setUpSimpleExoPlayer();
Log.d("EXO", "onCreate: hh ");
initExoPlayer();
setUoGlPlayerView();
Log.d("EXO", "onCreate: kk");
setUpTimer();
SimpleExoPlayer simpleExoPlayer = this.audioMediaPlayer;
if (simpleExoPlayer != null) {
simpleExoPlayer.setPlayWhenReady(true);
}
}
catch (Exception e)
{
Log.d("EXO2", "onCreate: "+e.getMessage());
}


//Set Image Dynamically
// mPhotoEditorView.getSource().setImageResource(R.drawable.color_palette);
}


private void setUpSimpleExoPlayer() {


// Produces DataSource instances through which media data is loaded.

private void initExoPlayer()
{
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)));

// This is the MediaSource representing the media to be played.
// MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
// .createMediaSource(Uri.parse("http://demos.webmproject.org/exoplayer/glass.mp4"));
final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(getApplicationContext());
DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.samplevideo));


DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.memories));
try {
rawResourceDataSource.open(dataSpec);

Expand All @@ -175,15 +185,50 @@ public DataSource createDataSource() {
}
};
MediaSource videoSource = new ExtractorMediaSource.Factory(factory).createMediaSource(rawResourceDataSource.getUri());
player = ExoPlayerFactory.newSimpleInstance(this);
player.prepare(videoSource);
player.setPlayWhenReady(true);
audioMediaPlayer = ExoPlayerFactory.newSimpleInstance(this);
audioMediaPlayer.prepare(videoSource);
audioMediaPlayer.setPlayWhenReady(true);
audioMediaPlayer.setVolume(0.4f);

} catch (RawResourceDataSource.RawResourceDataSourceException e) {
e.printStackTrace();
}


}


private void setUpSimpleExoPlayer() {


// Produces DataSource instances through which media data is loaded.
if(this.audioMediaPlayer==null) {

DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)));

final RawResourceDataSource rawResourceDataSource = new RawResourceDataSource(getApplicationContext());
DataSpec dataSpec = new DataSpec(RawResourceDataSource.buildRawResourceUri(R.raw.samplevideo));


try {
rawResourceDataSource.open(dataSpec);

DataSource.Factory factory = new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return rawResourceDataSource;
}
};
MediaSource videoSource = new ExtractorMediaSource.Factory(factory).createMediaSource(rawResourceDataSource.getUri());
player = ExoPlayerFactory.newSimpleInstance(this);
player.prepare(videoSource);
player.setPlayWhenReady(true);

} catch (RawResourceDataSource.RawResourceDataSourceException e) {
e.printStackTrace();
}
}


// SimpleExoPlayer

Expand All @@ -194,9 +239,14 @@ public DataSource createDataSource() {
private void setUoGlPlayerView() {
ePlayerView = new EPlayerView(this);
ePlayerView.setSimpleExoPlayer(player);
ePlayerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// ePlayerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
ePlayerView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -2));
((MovieWrapperView) findViewById(R.id.layout_movie_wrapper)).addView(ePlayerView);
ePlayerView.onResume();
ePlayerView.setPlayerScaleType(PlayerScaleType.RESIZE_FIT_WIDTH);
AppCompatImageView appCompatImageView = new AppCompatImageView(this);
appCompatImageView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
((FrameLayout) findViewById(R.id.layout_movie_wrapper)).addView(appCompatImageView);
}

private void setUpTimer() {
Expand Down Expand Up @@ -234,6 +284,10 @@ private void releasePlayer() {







private void handleIntentImage(ImageView source) {
Intent intent = getIntent();
if (intent != null) {
Expand Down Expand Up @@ -261,7 +315,7 @@ private void initViews() {
mRvTools = findViewById(R.id.rvConstraintTools);
mRvFilters = findViewById(R.id.rvFilterView);
mRootView = findViewById(R.id.rootView);
Bitmap bitmapEmpty = Bitmap.createBitmap(2000, 2000, Bitmap.Config.ARGB_8888);
Bitmap bitmapEmpty = Bitmap.createBitmap(3000, 3000, Bitmap.Config.ARGB_8888);
mPhotoEditorView.getSource().setImageBitmap(bitmapEmpty);

// imgUndo = findViewById(R.id.imgUndo);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_edit_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="675dp"
android:layout_marginTop="685dp"
android:layout_marginEnd="411dp"
android:layout_marginRight="411dp"
android:layout_marginBottom="56dp"
Expand Down
Binary file added app/src/main/res/raw/memories.mp3
Binary file not shown.

0 comments on commit ec174f4

Please sign in to comment.