Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert delay for audio forwarding #5114

Open
1 task done
vinniec2 opened this issue Jul 18, 2024 · 9 comments
Open
1 task done

insert delay for audio forwarding #5114

vinniec2 opened this issue Jul 18, 2024 · 9 comments

Comments

@vinniec2
Copy link

vinniec2 commented Jul 18, 2024

Is your feature request related to a problem? Please describe.
Well, I read about the problem with android 11. So to get the audio forwarding to work I open scrcpy, unlock the phone, close scrcpy and restart it with the --require-audio parameter. It's a little bit inconvenient.

Describe the solution you'd like
insert a delay to the sound forwarding request so that you don't have to unlock the phone and restart scrcpy with the --require-audio parameter while the screen remains on.

Describe alternatives you've considered
add a shortcut to turn sound forwarding on and off while scrcpy is running

Additional context
Thanks a lot, scrcpy is fantastic.

@rom1v
Copy link
Collaborator

rom1v commented Jul 18, 2024

insert a delay to the sound forwarding request

No, this delay is unknown. The prerequisite is to unlock the phone before starting scrcpy for Android 11.

restart it with the --require-audio parameter.

This parameter is not really necessary (it just makes scrcpy fail if audio capture fails).

add a shortcut to turn sound forwarding on and off while scrcpy is running

This must be known on start (the parameter is passed to the server on start, the recording feature depends on whether audio is enabled or not, etc.).

@vinniec2
Copy link
Author

vinniec2 commented Jul 18, 2024

No, this delay is unknown. The prerequisite is to unlock the phone before starting scrcpy for Android 11.

I don't really know how it works, I was speculating that audio forwarding could be activated afterward

This parameter is not really necessary (it just makes scrcpy fail if audio capture fails).

but if I don't use it, the sound is always heard from the cell phone speakers.

This must be known on start (the parameter is passed to the server on start, the recording feature depends on whether audio is enabled or not, etc.).

I understand, though, if the audio forwarding is not enabled, it's not even interesting to do the recording in the end (I'm assuming that you're only referring to the audio recording and that the video recording is not affected, but my guess is again speculation).

@rom1v
Copy link
Collaborator

rom1v commented Jul 18, 2024

but if I don't use it, the sound is always heard from the cell phone speakers.

No, this is unrelated: the sound is forwarded is capture works (typically when your phone is unlocked and the workaround for Android 11 works), it is kept on the device if capture does not work.

The option --require-audio just changes the behavior of scrcpy when audio capture fails:

  • without the option, if audio capture fails, scrcpy mirrors only the screen and the audio is kept on the device;
  • with the option, if audio capture fails, scrcpy exits with an error.

I'm assuming that you're only referring to the audio recording and that the video recording is not affected

When you record with --record=file.mp4, both video and audio (if present) are muxed into the same file, and the muxer must know if audio is enabled or not from the start.

@vinniec2
Copy link
Author

vinniec2 commented Jul 18, 2024

No, this is unrelated...

OK, I must have misunderstood the behavior of --require-audio

When you record with --record=file.mp4, both video and audio (if present) are muxed into the same file, and the muxer must know if audio is enabled or not from the start.

I understand, and I also understand that conceptually it's less problematic to do this than to go and create exception after exception.
Wouldn't there be a way to unblock the phone and start scrcpy without having to start it twice manually?
The only idea I can think of would be the inelegant idea of doing a script using the timeout command.
do you have any ideas?

@rom1v
Copy link
Collaborator

rom1v commented Jul 18, 2024

Wouldn't there be a way to unblock scrcpy without having to start it twice manually?

Start it once once your phone is unlocked.

@vinniec2
Copy link
Author

I'm in a special situation, I use the phone connected to 20 feet of cable in another room. let's say I use scrcpy just so I can use the phone remotely

@vinniec2
Copy link
Author

till now this is the only things I'm capable to do:
scrcpy --time-limit=5 && echo start
*manualli unlock the phone
scrcpy --require-audio

@rom1v
Copy link
Collaborator

rom1v commented Jul 18, 2024

OK, I understand this can be an issue.

However, supporting Android 11 for audio is already a dirty hack (supporting only Android 12 would have be cleaner), I don't want to add more hacks/configuration to the hack.

For your use case, you can delay audio capture by adding a call to SystemClock.sleep() just before this code:

startWorkaroundAndroid11();
try {
tryStartRecording(5, 100);
} finally {
stopWorkaroundAndroid11();
}

@vinniec2
Copy link
Author

ok many thanks, I will try as soon as I understand how to compile the packages for android :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants