I'm working on an app for a band, which consists of several different activities such as an agenda, news section, album section et cetera.
Since it's for a band, I would like to play the band's songs in the background.
This isn't such a problem, but I would like to show a small music player on the bottom of all activities so users can always stop, skip, or replay a song if they want to. An example of this can be found in the apps of Mobile Roadie, for instance.
However I have no idea how to do this. My best guess is creating a music player class with its own layout, and including this at the bottom of each activity/layout. But since every activity starts in its own thread, I'm guessing this would reset the player for each activity.
So, how would I go about adding a common music player to all of my activities, where the state of the music player would be maintained?
For an example, download any of the music based apps of Mobile Roadie and you'll know what I mean.
I decided on using Fragments, but I'm not sure if I can use those in already existing activities. All the examples I found focus on completely new projects, and not already existing ones.
So in short, can you create fragments and use them in already existing activities? (such as showing the music player on top of the existing agenda activity)
I suggest you doing it the following way. Since music playing state must be retained in all the activities, you have to use a service to achieve this. Also you need a control panel, which must exist separately from activities. The best method to do it is by using fragments. Create a fragment which connects to the service and provides an UI to control it, then add this fragment to all the activities where you need it.
Related
I have created an exercise app with text-to-speech functionality that says exercise name and sound when it's time to rest. but when I turn the screen off app keeps working making the sound and saying the exercise name. I think it has something to do with activity lifecycle, but I am a beginner in android development, so I don't quite know them.
How can I make the app stop working when the screen is off?
You have to pause your TTS manager when your activity/fragment goes to the onPause()/onStop() state and becomes not visible to the end user.
Please, read about activities/fragments lifecycle and determine which state would be the best solution for your case. You can either override these lifecycle methods directly (the easiest way) or you can use the Jetpack Lifecycle lib to create lifecycle-aware components (a cleaner approach if your TTS manager implementations exists as a separate class (and it should be so)).
This is an existing app with around 15 different activities. I need to have a video player that will keep playing at the top while the user can navigate throughout the app.
Is the only way to accomplish this by refactoring everything into a main activity and then just have the video player in a separate fragment? One added complication is that I need to support pager view activities but have the video player at the top that won't change when the user swipes through the pages.
Any suggestions would be appreciated.
Use framelayout with video player and fragments below it which keeps changing
You could use the same trick some apps (i.e. Facebook Messenger) are using - add a view to android.view.Window.
What will be different is that you would hide that view anytime user navigates away from your application.
It might not be the most elegant solution, but it'd keep changes to all your views to minimum.
See this article for some samples.
I'm currently developing android app using eclipse. Basicaly I want to make two activities play the same music without re-playing. Anyone know how to do that?
I am not sure, but you could create some static MediaPlayer object that would be shared across two activites.
Also you could look at Service that would could be bind to any of those activites and would start playback and play without depending on Activites.
I am developing a Quiz game application which is being developed completely but at various activities of my game different type of sounds files are played on every correct and wrong answer and respective theme sounds also plays at background.
But the problem arises when i want to stop or mute and start all the instances of media player running in various activities on click of mute and sound button in launcher activity.Can anyone help me out to bring out a logic of achieving this.I have dig into the logic a lot but cant find any concept to achieve this thats why no code to show.Because its totally logic based.
You can use a global class that contains "static" mediaplayer(s). When you need to stop, start or pause a mediaplayer, you can use
Global.mp1.stop();
Global.mp2.pause();
Global.mp3.start();
etc.
this is my first post on stack overflow so hoping you can help.
We are developing an Android App, that requires an audio player to always be available, no matter what activity you are on. Ideally, we want this to be a "pop up" style player that is accessible when you tap the screen or tab an always visible button (e.g. on the action bar). However, the player needs to overlay the activity you are on, and continue playing the audio as you move between activities and (ideally) multi task within your device.
I have looked into various options for this, and wonder if a service is the best way to go. The other option I am considering is a transarent activity. But I am open to suggestions!
Can anyone offer any guidance? Thanks in advance.
I think that service, playing the tracks is the best way to go.
For the player visual interface, you should have one view, which will be included wherever you need it.
When you open this view, you will get the information from the service (what track are you on, where exactly in the track) and initialize with those results.
At least this is my suggestion approach to the task. Good luck!
Have tried considering making it an android widget? It remains on the home screen and user can play music and get back to other tasks.
But not sure if it will meet your overlay criteria(Which I quite didn't understand.. :))
Check out Androids MediaPlayer-Class. This should prevent you with all nessesary playback functions. On how to create your player-controll-interface on Androids Action-Bar, check Googles Tutorial. But note that the ActionBar is available since Android 3.0, not in previous version!