Comments (5)
I don't think LoadControl
is the right place to be doing this. It feels like it's too deep in the player.
If you'd like to push your logic for starting playback just inside of the player, so that it works for commands via the MediaSession
(and any other UI component), then you could use ForwardingPlayer
. This is completely untested, but I'd imagine it would look something like:
class BtPlayer extends ForwardingPlayer {
public BtPlayer(ExoPlayer player) {
super(player);
player.setHandleAudioBecomingNoisy(true);
}
@Override
public void prepare() {
if (blockPlayback()) {
return;
}
super.prepare();
}
@Override
public void play() {
if (blockPlayback()) {
return;
}
super.play();
}
@Override
public void setPlayWhenReady(boolean playWhenReady) {
if (playWhenReady && blockPlayback()) {
return;
}
super.setPlayWhenReady(playWhenReady);
}
private boolean blockPlayback() {
// Return whether playback should be blocked from starting
}
}
You can then wrap your ExoPlayer
inside an instance of this class, and pass the BtPlayer
to the media session and any other UI components.
from media.
I think this should be done outside of the player. In other words, you should query whether there's a bluetooth headset connected before you prepare your ExoPlayer instance. ExoPlayer's audio-becoming-noisy handling might be sufficient for stopping the audio, but it's probably cleaner and more symmetric if you also handle this outside of the player. In other words, listen for the headset disconnecting, and stop the player when this occurs.
How to query bluetooth connected devices is outside the scope of this issue tracker, but you should be able to find what you need online. For example https://stackoverflow.com/questions/4715865/how-can-i-programmatically-tell-if-a-bluetooth-device-is-connected has some sample isBluetoothHeadsetConnected
methods that might be useful to you.
from media.
@ojw28 Thanks. That makes sense, and I've got docs on how to check and connect to the bluetooth headset.
It's not perfect, If the app laucnhes and then bluetooth disconnects before playback is started, I'll be in the same place. I can guard any play button presses, but it doesn't help for commands via the MediaSession, so I was hoping there was a nice approach to do this in ExoPlayer/Media3. Maybe show up via affecting availableCommands? Maybe interject during the LoadControl before it continues? I understand if not, and if there is some clean way to add, I'll suggest putting up a PR.
Would there be a downside to using LoadControl?
from media.
Thanks I'll try that or fallback to external logic at all points before playing.
Thanks.
from media.
The above solution has worked reasonably well, but it looks like to avoid errors like #167.
We will need to implement google/horologist#562 and use playback suppression for this.
from media.
Related Issues (20)
- OOM probably due to bad file
- Playback speed doesn't work on some devices with Audio Offload Enabled
- How to pass the tag in MediaItem to the customData of DataSpec?
- Android Auto Grid Layout with Media3 HOT 4
- Exoplayer.release did not free memory? Is it a Known issues??2.11.8 and 2.19.1
- Exoplayer does not resume once the Ad creative load is blocked via Charles
- "Session ID must be unique. ID=" when building a session HOT 4
- Rename setShowPlayButtonIfPlaybackIsSuppressed in MediaSession.Builder
- i'm facing an issue regarding the media3 exo player controlls position in a horizoantal tab . HOT 1
- Controlls position in a horizontal orientation with RESIZE_MODE_FILL HOT 2
- Add charles/fiddler... proxy block when playing hls media
- Player does not upscale LL Stream once it get to lowest resolution HOT 6
- Video is cut on the edge when using Compose and uses RESIZE_MODE_ZOOM - Only Android 14 HOT 1
- [CMCD] Too many buffer starvation reports HOT 5
- Equalizer support
- ERROR_CODE_IO_UNSPECIFIED error on HLS stream HOT 10
- TTML subtitles - Opacity not compliant with TTML specification HOT 6
- [Transformer] Overlay rotation around the X and Y axles HOT 2
- How to set defaultPositionUs of a Window in the Timeline? HOT 2
- Non-Exoplayer TimeBar with Exoplayer Function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media.