erfane.r
سه شنبه 06 فروردین 1392, 18:04 عصر
سلام دوستان.وقتتون بخیر
من 2 تا اکتیوی دارم که اکیتیوتی اولم اسمش SoundActivityهستش و کد زیر رو توش نوشتم.اکتیویتی دومم هم اسمش Sound هستش که از هنگام ساخت تغییری توش ندادم.وهم چنین توی فایل های دیگه هم تغییری ایجاد نکردم.مشکلم اینجاست که نمی دونم فایل10.mp3 کجا بریزم؟وهم چنین کد زیر اصلا موزیک پخش نمی کنه و فقط button شکلاش عوض می شه.
ممنون دوستان
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="10.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.pl ay);
}
private void setListeners(){
buttonPlayStop.setOnClickListener(new OnClickListener(){
public void onClick(View v){
buttonPlayStopClick();
}
});
}
private void buttonPlayStopClick(){
if(!boolMusicPlaying){
buttonPlayStop.setBackgroundResource(R.drawable.pl ay);
playAudio();
boolMusicPlaying=true;
}
else{
if(boolMusicPlaying){
buttonPlayStop.setBackgroundResource(R.drawable.pa use);
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();
}
}
}
من 2 تا اکتیوی دارم که اکیتیوتی اولم اسمش SoundActivityهستش و کد زیر رو توش نوشتم.اکتیویتی دومم هم اسمش Sound هستش که از هنگام ساخت تغییری توش ندادم.وهم چنین توی فایل های دیگه هم تغییری ایجاد نکردم.مشکلم اینجاست که نمی دونم فایل10.mp3 کجا بریزم؟وهم چنین کد زیر اصلا موزیک پخش نمی کنه و فقط button شکلاش عوض می شه.
ممنون دوستان
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="10.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.pl ay);
}
private void setListeners(){
buttonPlayStop.setOnClickListener(new OnClickListener(){
public void onClick(View v){
buttonPlayStopClick();
}
});
}
private void buttonPlayStopClick(){
if(!boolMusicPlaying){
buttonPlayStop.setBackgroundResource(R.drawable.pl ay);
playAudio();
boolMusicPlaying=true;
}
else{
if(boolMusicPlaying){
buttonPlayStop.setBackgroundResource(R.drawable.pa use);
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();
}
}
}