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.
Related
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'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.
I'm wondering, if there is any predefined sounds in Android that I can use in my application.
I was trying to use a class called SoundManager which is build specifically for sound playing in an efficient way.
I realized that what I need is much much smaller than this class. I need a click sound when the button is clicked and a navigation sound when the user navigate through a menu or a set of buttons.
I guess there is something in the android API fit to my purpose but I could not find it.
any help please in finding it and hoe to use it?
You could look into the View.playSoundEffect api. This method accepts a SoundEffectConstants value where, among others, a CLICK constant is available.
Using the MediaPlayer it's really simple, see for instance this SO thread:
Android - play sound on button click - Null pointer exception
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!
Actually, I found lots of answers for my questions but this time I am totally stuck.
My question is very easy. I am building a radio streaming application for .pls streams and when the user press the home button, I want my application to continue working. I think lots of you know ebuddy and Skype or the basic media players. They are putting themselves to notification bar and you can easily reach them from this place. I tried to create a notification for my app, but when I click the icon on the notification bar, I can't reach my app. It directly opens a new version of my app and I can't control the streaming, the initial working app is no longer existing.
You may want to read the descriptions for LaunchMode: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
You want to launch your Activity as singleInstance
Edit: maybe singleTask would be better.
This is the workflow you want to achieve:
All background work has to be done by a service. Implementing one is quite simple, almost as creating an activity.
There are many examples on how to do it:
http://developer.android.com/reference/android/app/Service.html
http://marakana.com/forums/android/examples/60.html
http://code.google.com/p/openmobster/wiki/AndroidService
You need the actual music playing part - or the part that should continue running in the background - to be a service, and the gui to be an activity. The notification you made should bring your activity gui to the front with a flag_activity_reorder_to_front.