• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps a problem when using background music in application

erfane

Lurker
hi friends.
I have two activity.My frist activity 's name is soundActivity & the second activity is secend.This code was written in soundActivity & an other files donot change but this code isnot run.
please help me:)
HTML:
package com.sound;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class SoundActivity extends Activity {
	Intent serviceIntent;
	private Button buttonPlayStop;
	private boolean boolMusicPlaying=false;
	String strAudioLink="dj.mp3";
    /** Called when the activity is first created. */
   // @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        try{
        	serviceIntent =new Intent(this,second.class);
        	initViews();
        	setListeners();
        }catch(Exception e){
        	e.printStackTrace();
        	Toast.makeText(getApplicationContext(), e.getClass().getName()+" "+e.getMessage(), Toast.LENGTH_LONG).show();
        	
        }
    }
    
    
    private void initViews(){
    	buttonPlayStop= (Button) findViewById(R.id.button1);
    	buttonPlayStop.setBackgroundResource(R.drawable.play);
    }
    
    private void setListeners(){
    	buttonPlayStop.setOnClickListener(new OnClickListener(){
    		public void onClick(View v){
    			buttonPlayStopClick();
    		}
    	});
    		}
    
    private void buttonPlayStopClick(){
    	if(!boolMusicPlaying){
    		buttonPlayStop.setBackgroundResource(R.drawable.play);
    		playAudio();
    		boolMusicPlaying=true;
    	}
    	else{
    		if(boolMusicPlaying){
    			buttonPlayStop.setBackgroundResource(R.drawable.pause);
    			stopSecond();
        		boolMusicPlaying=false;
    		}
    			
    		}
    	}


	private void stopSecond() {
		
		try{
			stopService(serviceIntent);
		}catch(Exception e){
			e.printStackTrace();
			Toast.makeText(getApplicationContext(), e.getClass().getName()+" "+e.getMessage(), Toast.LENGTH_LONG).show();
	    	
			
		}	
		boolMusicPlaying=false;
	}


	private void playAudio() {
	serviceIntent.putExtra("sentAudioLinker", strAudioLink);
	try{
		startService(serviceIntent);
	}catch(Exception e){
		e.printStackTrace();
		Toast.makeText(getApplicationContext(), e.getClass().getName()+" "+e.getMessage(), Toast.LENGTH_LONG).show();
    	
		
	}
	
		
	}
    }
 
Back
Top Bottom