As far as I know, with the YouTube API for Android, the player automatically stops when it's out of view. For example, when the app is closed or when another view is positioned on top of the player.
But I've seen this application: https://play.google.com/store/apps/details?id=com.mixerbox.mixerbox that seems to have found a workaround for this. In this app, when you close it, the video doesn't stops and continues playing in the background.
Anyone know how this can be achieved?
To play only the audio of a YouTube video violates the YouTube API Terms of Service:
Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to:
9. promote separately the audio or video components of any YouTube audiovisual content made available through the YouTube API;
For educational purposes take a look at the Services developer guide.
A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background
The MixerBox app you mention most likely has a Service that it delegates the play back of the video's audio to when its' Activity's onPause() callback is executed by the system. That is how MixerBox allows you to navigate away from the application and you can still here the audio playing from the video.
Related
My android java app has Offline Video feature like the YouTube app. I do not use android.app.DownloadManager because it does not support pausing the downloads(or as I know).
I have been using a third party download manager library(tonyodev.fetch2) and it does the work done but the problems are:
How can I make the download independent of the app closing/opening etc and also being able to control it when required from an Activity.
If I use a Service for the above problem, what do I use, IntentService or just normal Service keeping in mind I have to know about the ongoing downloads and control it(pause/stop/resume) from any activity.
I have been using android worker class which extents ListenableWorker but I cant seem to make things work as required.
I have been struggling with this for a long time now any help is welcome, or a totally new approach for this particular problem.
I am developing an application that will be use to record video in background once the video calling starts.I googled about it but didn't get any solution. Many articles say that it is not possible.
Please let me know the way to implement the functionality
What you can do is that you can simply record the screen of the phone. There are several libraries available for implementing that. You can trigger or alert the library to start recording the screen once the video call starts.
Can i make a service which recognize voice even when phone is idle or screen off? I mean can phone listen to what the user will say even on idle state.
This is the entire program on how to make that happen.
http://developer.android.com/guide/topics/media/audio-capture.html
That shows how to record audio, the same implementation could be used to listen for audio.
Also, DEV GUIDE on what services are.
Right from developer.android.com
A service is a component that runs in the background to perform
long-running operations or to perform work for remote processes. A
service does not provide a user interface. For example, a service
might play music in the background while the user is in a different
application, or it might fetch data over the network without blocking
user interaction with an activity. Another component, such as an
activity, can start the service and let it run or bind to it in order
to interact with it. A service is implemented as a subclass of Service
and you can learn more about it in the Services developer guide.
This should give you all the information you need:
http://developer.android.com/guide/topics/fundamentals/services.html
You will have to aquire a wakelock in a service too keep the phone from sleeping so you can record audio. You can probably stick with a PARTIAL_WAKELOCK since you will not need the screen to be on.
You also need the wakelock permission.
Keeping the device active and processing sound continuously will however not be sensible for any implementation I can think of.
It is a horrible idea for most purposes since it will drain your battery in a matter of hours (tops).
I've been working at getting a background audio recorder (while screen is off), and these are the options I've found:
A full wakelock lets you keep recording, but keeps the screen on. (not ideal)
A partial wakelock would be good, except it doesn't actually work -- at least on my phone. (the cpu is kept active, but the data from the microphone becomes just 0s after a couple minutes)
Use a foreground service which starts a background thread that records the audio. This is the best since it lets the screen turn off, while still recording indefinitely.
See here for an example: https://stackoverflow.com/a/57260468/2441655
I have searched, but can not find the answer I'm looking for.
I want to create a service and be able to call a function to play an audio file.
I have 5 different intents that will be using the service to play 5 different audio files (one each) and I have a stop button in each one. Whichever stop button is pressed I want it to stop all audio that has been called from the service.
Does any one have an example code which I can use? (Something close to what I'm looking for.)
I'm building a media player to understand how Android works, and I have a service that queues audio files to play them. You can get the full source code from github.
The service is in /src/com/augusto/mymediaplayer/services
I'm not using Intens, but binding the service to the Activities that use it, but changing it to receive intents shouldn't be that hard. Just in case, this service runs ok on Android 1.6+.
I think that to change it to receive intents, you'll need to change onStart() and do a switch on the intent.
I know that this doesn't answer your question 100% but it's a place to start :).
I know this in general is beyond the scope of SO, but I am looking for some basic yes/no info to see if it is even feasible to proceed... I am thinking about building and Android 'note-taking/annotation' app that runs 'over' other installed Android apps, such as the web browser for example.
Essentially, while the user is browsing, my app would be running in the bg as a service, and then they could activate it which would then essentially intercept user inputs and translate those on a transparent canvas over the web browser into lines, shapes, etc. The user could then take a screen-cap of their marking with the underlying web page, which would be stored to the sd card.
This is a very good idea and a great question, but sadly, I do not believe it is possible.
The way Android is designed only one Activity can have focus at a time, while a Service could run in the background, the user would not be able to interact with it. The user can only interact with the currently active Activity.
Again, love the idea, but it is sadly not supported.
You might be able to achieve this with the WindowManager service. You can then use that to call addView() with a view of type TYPE_SYSTEM_ALERT, or possibly TYPE_SYSTEM_OVERLAY (but see the notes in the documentation about taking input focus).
I haven't tried it myself, but I've seen several apps (often dictionary apps that translate whatever words you tap on) that do overlays, and they always seem to require the SYSTEM_ALERT_WINDOW permission.