aws-samples / amazon-ivs-broadcast-android-sample

MIT No Attribution
10 stars 8 forks source link

Preview not appearing #11

Open Anu07 opened 2 years ago

Anu07 commented 2 years ago

I have integrated the same code into my project. But it is showing blank preview. Please help.

caleighm commented 2 years ago

Hi @Anu07 , can you reproduce the problem using the provided sample app?

If not, what modifications have you made to the sample app?

Can you please set the broadcast configuration to DEBUG log level, and then attach the DEBUG logs where you reproduce the issue to this ticket?

Finally, if you have a business contact at IVS, please contact them as well so that we can provide you with internal support.

Thanks!

Anu07 commented 2 years ago

I have integrated the sample app code (Excluding Room and dagger injection). Rest all has been used as is.

caleighm commented 2 years ago

Hi @Anu07 , I will need more information to help you debug further. Can you please attach DEBUG logs? What device are you using to test? Are you able to reproduce the problem with the sample app on Github, or is this only a problem in your modified application?

Anu07 commented 2 years ago

import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.amazonaws.ivs.broadcast.BroadcastException; import com.amazonaws.ivs.broadcast.BroadcastSession; import com.amazonaws.ivs.broadcast.Device; import com.amazonaws.ivs.broadcast.ImageDevice; import com.amazonaws.ivs.broadcast.ImagePreviewView; import com.amazonaws.ivs.broadcast.Presets; import com.amazonaws.ivs.player.Cue; import com.amazonaws.ivs.player.Player; import com.amazonaws.ivs.player.PlayerException; import com.amazonaws.ivs.player.Quality; import com.tpss.votamea.R; import com.tpss.votamea.adapters.UpcomingStreamListAdapter; import com.tpss.votamea.base.BaseActivity; import com.tpss.votamea.modals.upcomingStream.DataItem;

public class BroadcastActivity extends BaseActivity { private Player player; private DataItem streamData; private String key; private String endpoint; BroadcastSession.Listener broadcastListener = new BroadcastSession.Listener() { @Override public void onStateChanged(@NonNull BroadcastSession.State state) { Log.d("TAG", "State=" + state); }

            @Override
            public void onError(@NonNull BroadcastException e) {

            }

        };
private BroadcastSession broadcastSession;
private Button startBttn;
private Button stopBttn;
private LinearLayout previewHolder;

@Override
protected int getLayoutId() {
    return R.layout.activity_broadcast;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutId());
    player = Player.Factory.create(this);

    streamData = getIntent().getParcelableExtra(UpcomingStreamListAdapter.MODELDATA);
    key = streamData.getRtmp().split("/app")[1];
    endpoint = streamData.getRtmp().split("/app")[0] + "/app";
    setUpBroadcastSession();
    broadcastSession.awaitDeviceChanges(() -> {
        for(Device device: broadcastSession.listAttachedDevices()) {
            // Find the camera we attached earlier
            if(device.getDescriptor().type == Device.Descriptor.DeviceType.CAMERA) {
                previewHolder = findViewById(R.id.previewHolder);
                ImagePreviewView preview = ((ImageDevice)device).getPreviewView();
                preview.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MATCH_PARENT,
                        LinearLayout.LayoutParams.MATCH_PARENT));
                previewHolder.addView(preview);
            }
        }
    });

// surfaceView = findViewById(R.id.preview_view); // Set up to receive playback events and errors startBttn = findViewById(R.id.start); stopBttn = findViewById(R.id.stop); startBttn.setOnClickListener(v->{ broadcastSession.start(endpoint, key); }); stopBttn.setOnClickListener(v->{ broadcastSession.stop(); }); }

public void setUpBroadcastSession(){
    Context ctx = getApplicationContext();
    broadcastSession = new BroadcastSession(ctx,
            broadcastListener,
            Presets.Configuration.STANDARD_PORTRAIT,
            Presets.Devices.FRONT_CAMERA(ctx));
}

@Override
protected void onDestroy() {
    super.onDestroy();
    previewHolder.removeAllViews();
    broadcastSession.release();
}

}

caleighm commented 2 years ago

Hi @Anu07 , thanks for attaching your source code. Could you please attach the device logs where you reproduce the problem as a text file? Thanks!

Anu07 commented 2 years ago

Sure, here it is: logs.txt

caleighm commented 2 years ago

Hi @Anu07 , the logs show that your stream is unable to start due to an error:

2022-01-08 01:39:26.463 25711-26670/com.tpss.votamea E/AmazonIVS: RTMP Entered error state with error RTMP:5:Could not start the stream. This can happen when the previous stream did not disconnect properly. Wait a couple seconds and then try again.

Can you confirm that the endpoint URL and stream key you are using will work with the sample app on Github (that is, without your code changes)?

Anu07 commented 2 years ago

My endpoint and key are working fine in demo app. PRoblem is not about starting stream. I can see some traces in AWS dashboard. but camera preview is not showing that is the real trouble.

Anu07 commented 2 years ago

Also, I am getting this error too frequently ERROR: [rtmp] [5 - 0] Could not start the stream. This can happen when the previous stream did not disconnect properly. Wait a couple seconds and then try again.

caleighm commented 2 years ago

Hi @Anu07 , if you're getting that error repeatedly, please ensure that no other device or application is streaming to that endpoint simultaneously.

Also, an incorrect stream key will result in the same thing. But if the same stream key is working fine with the Github sample app (without your code changes), that is likely not the problem here.

Is it possible you are running the app in an emulator and on a test device at the same time? What test device(s) are you using, and what Android OS version?

Can you please attach full device logs (not just filtered to the app)?

It might also be helpful to compare your layout .xml file to the one in our sample app, if you made any changes to it.

Anu07 commented 2 years ago

I tried with another rtmp url and key. It is still throwing same error. And, it is with sample app too.

caleighm commented 2 years ago

Hi @Anu07 , thanks for sharing. I've removed the logs and screenshot from your post so that we are not sharing your stream key publicly.

I strongly recommend you rotate your stream key at this time, to prevent others from being able to use it. We are going to update our sample app to scrub that information from the logs, as well.

In the meantime, I am taking a look at the logs you've attached. Thanks and apologies for this.

caleighm commented 2 years ago

Hi @Anu07 , can you please reach out to your IVS business contact with the problem you're experiencing with your endpoint URL and stream key, which leads to the [rtmp] [5 - 0] error? We will need server-side information to troubleshoot that with you, which is not appropriate for a public forum.

If you do not have an IVS business contact, please let me know.

Finally, are you able to see the preview on the Github sample app? That is, is the preview only missing on your own custom app?

Anu07 commented 2 years ago

Hi @Anu07 , thanks for sharing. I've removed the logs and screenshot from your post so that we are not sharing your stream key publicly.

I strongly recommend you rotate your stream key at this time, to prevent others from being able to use it. We are going to update our sample app to scrub that information from the logs, as well.

In the meantime, I am taking a look at the logs you've attached. Thanks and apologies for this.

I am not using stream key anywhere else

Anu07 commented 2 years ago

Hi @Anu07 , can you please reach out to your IVS business contact with the problem you're experiencing with your endpoint URL and stream key, which leads to the [rtmp] [5 - 0] error? We will need server-side information to troubleshoot that with you, which is not appropriate for a public forum.

If you do not have an IVS business contact, please let me know.

Finally, are you able to see the preview on the Github sample app? That is, is the preview only missing on your own custom app?

Preview is there. But after 5-7 secs it returns same error.

caleighm commented 2 years ago

Hi @Anu07 , thanks for replying quickly.

I am not using stream key anywhere else

Because the stream key was accidentally included in device logs you uploaded, I still strongly encourage you to rotate the stream key since it was exposed to the public.

Preview is there.

If the preview works on the sample app but not your custom application, try comparing your XML layout to the sample app. It's possible your view is not attached to the view hierarchy, or perhaps it is not being displayed.

The preview should work even without starting the broadcast session. So, while you are debugging the issue with the preview, you can remove the code that actually starts the broadcast session so that you avoid the RTMP error interrupting the flow.

But after 5-7 secs it returns same error.

To continue debugging the RTMP error, please reach out to your IVS business contact. This is a server issue and we'll need more information to continue debugging, but it can't happen in a public forum. Please let me know if you don't have a business contact at IVS.