Can I set the GLSurface view(Animation) as my background? - java

I'm developing a media player application in Android. I've an animation (Open Gl Surface View) which should run in background to my Activity when song is being played. Like the animation which we see when we are playing Windows Media Player.
How can I achieve the above scenario?

You can add glSurfaceView as a child to your main view.
something like:
mainLayout.addView(glSurfaceView);
this.setContentView(mainLayout);

the scenario you describe is pretty vague.
what you'll want is to create an activity that will have a GLSurfaceView with all you animations and interface, and running in a separates Thread your media playing code.
if this is not what your asking please give us more details
Jason

Related

Why does an activity playing a sound disturb the user interface?

I would like to show a notification and play a sound when the user taps onto that notification. It works somehow when I use an activity to play the sound, as I have written in my own answer to this question: How can I create a notification that plays an audio file when being tapped? (in this question and answer there is also the source code showing how I create the notification and how my PlaySoundActivity looks like.
Yet, I have realized, that while the sound is playing, the appearance of my main application changes and it will not be restored without closing the application.
I have created my application from the "Tabbed Activity" project template.
This is how it looks after being started:
And this is how it looks when I have tapped onto the sound notification (the sections are gone):
Can anyone explain why this happens? Is it a wrong approach to play sound using an activity? But it does not work here when I use a service, I hear nothing! How to solve that?
According to the Android developer reference, "almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)".
I had not done this. Therefore a new window was displayed, but there was no content.
The better solution for playing a sound is to use a PlaySoundService (service!!!) instead of an activity. It contains almost the same code as an activity would do, but the pending intent is created with PendingIntent.getService(...) instead of PendingIntent.getActivity(...). Using the wrong method does not result in an obvious error message, but the service won't work as expected.

Android: Video Player Like Dailymotion App

I want to develop video player like dailymotion app. The main thing that i want to achieve is it's rotation behaviour and full screen button action. When user rotate device or tap on full screen button the video player goes to full screen and video play continue without any intruption.
Currently i am using video view widget for Stream video. but when user rotate device. the video stop and video view activity reload and video view intilize again and then video play.
So please suggest me solution of this problem. Thanks in advance.
You can use below flags when registering your activity in manifest file
android:configChanges="orientation|screenSize|keyboardHidden"
and then in you activty class just override "onConfigurationsChanged()" method so that your activity won't restart when orientation changes.
One thing that you can try is to save video current position in "onConfigurationChanged()" so that after rotation when VideoView reinitialize itself you can continue to play video from that position.
ues ExoPlayer as base class and extend it as your own Custom Player. these issues are handled here. this is available on official android developer site
http://developer.android.com/guide/topics/media/exoplayer.html

android eclipse: switch activity briefly shows previous activity screen

I am sure this is a basic question, but I'm developing an Android app using ADK and Eclipse.
When I try to transition Activities, the screen goes black and then briefly shows the previous activity screen before "flipping" to the new screen.
I don't have any custom transitions; I'm using the default.
I don't have much going on in my onCreate event (EXCEPT: I load my background image during onCreate! Could it be this?)
I really am looking at a very snappy transition, like a game like Words with Friends, where it appears to switch "instantly".
This depends on what phone you're using since different phones use different anamations. Try to call finish(); on every activity but your main one for example.. Or finish them all when the user switches activities

Open mp3 files in android default media player on the same activity

I am developing an Android application in which I am showing a ListView of mp3 files from the sd card.
Now what I want is that when user clicks on any of the mp3 files it should start playing there on the same Activity. The code which I am using presently is not working for me to play audio files.
My code:
Uri uri = Uri.parse("/sdcard/music/sample.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
But this is something that I want. This is a screen Shot form android gingerbread
see this link here is a good example of getting all the music files and show in list and play when you click any item...
Display MusicList and play on itemClick
Another link
I suppose you should use another approach in case you want audio played in the same activity. I'd better initialize MediaPlayer object in this activity or as a background service.
In case of any questions feel free to ask.
UPDATE 1
In general case as I said you either need the MediaPlayer object in Activity or Music Service.
Now lets talk about controls.
You can simply put into your layout the block with controls and show/hide it when needed. MediaPlayer provides several convenient callbacks, so you will be able to update progressbar.
So, sum up:
Include controls into layout.
Include MediaPlayer into activity or make it work as a Service.
Bond controls to player.
???
PROFIT

is multiple activities and surface views the correct way to go?

I'm currently in the process of making one of my first android games and have come into some difficulty understanding how to make the transitions between screens.. for example:
My game starts its main activity, which then loads TitleScreen surface view which initializes its own thread
on tap I start a new intent which loads a new activity which loads GameView surface view which initializes its own thread
This all works fine when testing on my device (Evo 3d) but crashes on tap on my test bed, I'm using android x86 in virtual box for quick testing. Is this likely to be a problem in my code or a problem with the simulator?
Also I'm wanting to add a level select screen in between the title screen and the game screen and figured i could do this by creating another activity/surface view/thread combo, Is this acceptable coding practice or is this a wasteful/process heavy method?
You could create a variety of methods that you call from your onDraw method. Each method would draw one screen (game, level, score). To start simple a switch case in the onDraw checks the screen and then calls the right thing to draw.
If you want to have different layers, you should use different acitvities so that the background (game) is being paused while the scoreboard is active. This only makes sense if you want the background to be still visible or need the acitivites for other reasons.
But you should never have more than one surface view active at the same time, android doesnt like that.
I think its not good to use more activities for single application. Try to use ViewFlipper with number of xml layout files. Here you can apply transition effects very easily.
I am suggesting you it for transition effects, but you also check it once. I am also thinking which one is good.

Categories

Resources