Comments (3)
I don't think you can run the asyncio event loop from another thread (at least not yet). So I would say that is incorrect usage of asyncio. What are you trying to accomplish?
from pyatv.
I want to have an list of all HomePods and the can select one or multiple HomePods, were an live audio stream of my system Audio is played. I have found an workaround, wich is not that nice, but it works. I create like an thread with another process in it. And then it works.
from pyatv.
You can do that in asyncio, but you don't use threads. Instead use tasks. Something like this will stream to all HomePods and wait for it to finish:
from pyatv import scan, connect, const
import asyncio
import asyncio.subprocess as asp
TARGET_MODELS = [const.DeviceModel.HomePod, const.DeviceModel.HomePodGen2, const.DeviceModel.HomePodMini]
async def stream_to_device(device):
loop = asyncio.get_event_loop()
atv = await connect(device, loop)
process = await asp.create_subprocess_exec("C:\\Program Files\\ffmpeg\\ffmpeg.exe", "-f", "dshow", "-i", "audio=Home Pod (VB-Audio Virtual Cable)", "-acodec", "libmp3lame", "-f", "mp3", "-", stdout=asp.PIPE, stderr=None)
await atv.stream.stream_file(process.stdout)
async def main():
devices = await scan(asyncio.get_event_loop())
streams = []
for device in devices:
if device.device_info.model in TARGET_MODELS:
streams.append(asyncio.create_task(stream_to_device(device)))
await asyncio.gather(*streams)
if __name__ == "__main__":
asyncio.run(main())
I have not tested this, but should be mostly correct.
from pyatv.
Related Issues (20)
- atvscript push_updates - output_devices is not supported HOT 3
- Add atv-desktop-remote to list of projects that use pyatv HOT 2
- Replicate connection in iOS native App HOT 6
- Downgrade minimum Cryptography requirement to 3.4.8 HOT 2
- Verify compatibility with tvOS 18 HOT 9
- Switch to use uv instead of regular pip
- Replace pylint, isort and black with ruff
- Container in docker won't start HOT 1
- "atvremote -s <IP> previous" won't go back to the previous page within an app
- error in fetch metadata in "playing" command HOT 5
- Stream Live Audio Output to HomePod HOT 2
- Installing pyatv on a raspberry pi to work with node-red-contrib-apple-tv-x 1.0.3 HOT 2
- Install Problem HOT 6
- NSOSStatusErrorDomain with only some mp4 files HOT 1
- AttributeError: module 'lib' has no attribute 'EVP_CIPHER_CTX_ctrl'。macbook pro m1芯片笔记本,使用pyenv安装的python无法使用, HOT 11
- Expose new tvOS 18 Companion Remote features to API (e.g. now playing images, insight, upnext) HOT 5
- White light but no audio when streaming to HomePod Mini HOT 4
- atvproxy - streaming airplay content
- Working with pyatv on iOS with PythonKit and Python.framework
- How to find AppleTV on other network HOT 2
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 pyatv.