|  | 
	                
 
 
  
    | 
        
        Android ช่วยแก้code หน่อยครับ ผมเขียนวิทยุ Radio ออนไลน์ รันแล้วไม่มีเสียงครับ ทำไงดีๆๆๆๆ     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เอา Code ที่เขียนไว้มาดูดีกว่าครับ โหลดไฟล์มันเสี่ยงครับ  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-27 08:53:01 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | class : ShowUrl
package com.example.modelradio;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ShowUrl extends Activity implements View.OnClickListener{
	public static final String TAG="Radio";
	 public static  String station=
			 "org.example.radio.playradio";
	 private static String url;
	Intent int_radio;
	private TextView textUrl;
	private Button btnStart;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_radio);
		Log.d(TAG,"Start");
		
		
		textUrl=(TextView) findViewById(R.id.textView2);
		
		//get url from MainRadio
		String test =setUrl(url);
		textUrl.setText(test);
		Log.d("station","staton is : "+test);
		textUrl.setVisibility(View.VISIBLE);
		
		int_radio = new Intent(this,PlayService.class);
		 int_radio.putExtra("url_radio",test);
		
		 btnStart=(Button) findViewById(R.id.btn_option);
		
		 btnStart.setOnClickListener(this);
		
	}
	
	public  static String setUrl(String url) {
		ShowUrl.url = url;
		return url;
	}
	
	public void stopClick(View v){
			stopService(int_radio);
	}
	  private boolean isMyServiceRunning() {
		    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
		    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
		        if ("com.example.modelradio.PlayService".equals(service.service.getClassName())) {
		            return true;
		        }
		    }
		    return false;
		}
	  
	
	public void onClick(View v) {
	
		 if(isMyServiceRunning()){
			  Toast.makeText(getApplicationContext(),"Radio Service is already running...", Toast.LENGTH_LONG).show();
			  btnStart.setText("Stop");
		  }else{
			  startService(int_radio);
		  }
	}
	
}
 class PlayService
 
 package com.example.modelradio;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class PlayService extends Service {	
	MediaPlayer mediaPlayer;
	Boolean isPlaying = false;
	int noti_id=9988;
	NotificationManager mNM;	
	String url_radio;
	
	private final IBinder mBinder = new LocalBinder();
	@Override
	public IBinder onBind(Intent intent) {
		return mBinder;
	}	
	
	Thread thread = new Thread()
	{
		
		@Override
	    public void run() {
			try {	            
	            	
	            	try{
		            	mediaPlayer.setDataSource(url_radio);
		            	Log.d("url","url radio : "+url_radio);
		                mediaPlayer.prepare();
		                mediaPlayer.start();
	            	}catch(Exception e){
	            		e.printStackTrace();
	            	}finally{	            		
	            		sleep(200);
	            	}
	            	                
	            
	        } catch (InterruptedException e) {
	            e.printStackTrace();
	        }
	    }
	};
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		
		mediaPlayer = new MediaPlayer();
		mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		showNotification();
		
	}
	
	private void showNotification() {		
		Notification notification = new Notification(R.drawable.ic_launcher,null,System.currentTimeMillis());		
		notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;		
		Intent noti = new Intent(this, ShowUrl.class);
		noti.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);		
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0,noti, 0);		
		notification.setLatestEventInfo(this, "myRadio Playing Service","Radio Service is running...", contentIntent);		
		mNM.notify(noti_id, notification);
	}
	
	@Override
    public void onStart(Intent intent, int startId) {        
		super.onStart(intent, startId);
		if(thread.isAlive()){ 
	        
        	return;
        }
		
		Bundle extras = intent.getExtras();
		url_radio = extras.getString("url_radio");        
        Log.d("dbudf","url radio : "+url_radio);
       
        thread.start();
             
    }
 
    @Override
    public void onDestroy() { 
    	
    	if(mediaPlayer.isPlaying()){ 	
    		mediaPlayer.stop();
            mediaPlayer.release();
    	}
    	mNM.cancel(noti_id);
        super.onDestroy();
       
        
       
    }
    
    public class LocalBinder extends Binder {
    	PlayService getService() {
			return PlayService.this;
		}
	}
}
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-27 10:51:30 | By :
                            YouAreMyFeed |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-27 10:53:33 | By :
                            YouAreMyFeed |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | โค้ทนี้สำหรับเล่นไฟล์ radio แบบ dns ของ radio นะครับ ไม่ใช่ url แบบเว็ปที่เล่นเสียงผ่าน windows media ทั้วไป และถ้าเป็นพวก ไฟล์ .pls นี้ต้องอาศัยโปรแกรมอื่นครับวิธีการเขียนผมก็หาอยู่แต่หาเท่าไรก็ไม่เจอ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-10-06 18:28:30 | By :
                            เป็ด |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ผมยังเขียนไม่ถึงครับ ถ้าได้ศึกษาบ้างก็น่าจะช่วยตอบหรือแนะนำได้  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-10-07 09:33:09 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |