Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.59k stars 10.45k forks source link

insert delay for audio forwarding #5114

Open vinniec2 opened 1 month ago

vinniec2 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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:

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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:

https://github.com/Genymobile/scrcpy/blob/cc8e6133b0c9975ef2ed16086960e822ab750404/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java#L123-L128

vinniec2 commented 1 month ago

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