Şu Hatayı Alıyorum Yardım Edebilir misiniz?
MERHABA;
Arkadaşlar, bir radyo ile ugrasıyorum, play tusuna basınca progressDialog cıkarıp yayın gelene kadar ekranda tutmak istiyorum ama bir türlü cıkamadım işin içinden yardımcı olursanız sevinirim.
HATA :
04-15 13:47:08.602: E/WindowManager(427): at android.widget.ToggleButton.setChecked(ToggleButton.java:69)
04-15 13:47:39.132: E/AndroidRuntime(473): FATAL EXCEPTION: AsyncTask #1
04-15 13:47:39.132: E/AndroidRuntime(473): java.lang.RuntimeException: An error occured while executing doInBackground()
04-15 13:47:39.132: E/AndroidRuntime(473): at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.lang.Thread.run(Thread.java:1019)
04-15 13:47:39.132: E/AndroidRuntime(473): Caused by: java.lang.NullPointerException
04-15 13:47:39.132: E/AndroidRuntime(473): at com.ndeg.MainActivity.sendBufferingBroadcast(MainActivity.java:236)
04-15 13:47:39.132: E/AndroidRuntime(473): at com.ndeg.MainActivity.access$2(MainActivity.java:234)
04-15 13:47:39.132: E/AndroidRuntime(473): at com.ndeg.MainActivity$Servering.doInBackground(MainActivity.java:132)
04-15 13:47:39.132: E/AndroidRuntime(473): at com.ndeg.MainActivity$Servering.doInBackground(MainActivity.java:1)
04-15 13:47:39.132: E/AndroidRuntime(473): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-15 13:47:39.132: E/AndroidRuntime(473): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-15 13:47:39.132: E/AndroidRuntime(473): ... 4 more
04-15 13:47:40.902: E/WindowManager(473): Activity com.ndeg.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40558af8 that was originally added here
04-15 13:47:40.902: E/WindowManager(473): android.view.WindowLeaked: Activity com.ndeg.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40558af8 that was originally added here
04-15 13:47:40.902: E/WindowManager(473): at android.view.ViewRoot.<init>(ViewRoot.java:258)
04-15 13:47:40.902: E/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-15 13:47:40.902: E/WindowManager(473): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-15 13:47:40.902: E/WindowManager(473): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-15 13:47:40.902: E/WindowManager(473): at android.app.Dialog.show(Dialog.java:241)
04-15 13:47:40.902: E/WindowManager(473): at com.ndeg.MainActivity$Servering.onPreExecute(MainActivity.java:124)
04-15 13:47:40.902: E/WindowManager(473): at android.os.AsyncTask.execute(AsyncTask.java:391)
04-15 13:47:40.902: E/WindowManager(473): at com.ndeg.MainActivity$2.onCheckedChanged(MainActivity.java:57)
04-15 13:47:40.902: E/WindowManager(473): at android.widget.CompoundButton.setChecked(CompoundButton.java:124)
04-15 13:47:40.902: E/WindowManager(473): at android.widget.ToggleButton.setChecked(ToggleButton.java:69)
04-15 13:47:40.902: E/WindowManager(473): at android.widget.CompoundButton.toggle(CompoundButton.java:86)
04-15 13:47:40.902: E/WindowManager(473): at android.widget.CompoundButton.performClick(CompoundButton.java:98)
04-15 13:47:40.902: E/WindowManager(473): at android.view.View$PerformClick.run(View.java:9080)
04-15 13:47:40.902: E/WindowManager(473): at android.os.Handler.handleCallback(Handler.java:587)
04-15 13:47:40.902: E/WindowManager(473): at android.os.Handler.dispatchMessage(Handler.java:92)
04-15 13:47:40.902: E/WindowManager(473): at android.os.Looper.loop(Looper.java:123)
04-15 13:47:40.902: E/WindowManager(473): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-15 13:47:40.902: E/WindowManager(473): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 13:47:40.902: E/WindowManager(473): at java.lang.reflect.Method.invoke(Method.java:507)
04-15 13:47:40.902: E/WindowManager(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-15 13:47:40.902: E/WindowManager(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-15 13:47:40.902: E/WindowManager(473): at dalvik.system.NativeStart.main(Native Method)
KODLAR :
package com.ndeg;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;import android.support.v7.app.ActionBarActivity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;public class MainActivity extends ActionBarActivity {
private ToggleButton btn;
private ProgressDialog pd = null;
private Handler hand;
boolean mBufferBroadcastIsRegistered;
Intent bufferIntent;
private boolean isOnline;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hand = new Handler();
btn = (ToggleButton) findViewById(R.id.toggleButton1);
btn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//showPD(null);
/*if (mBufferBroadcastIsRegistered) {
unregisterReceiver(broadcastBufferReceiver);
mBufferBroadcastIsRegistered = false;
}*/
startService(new Intent(getApplicationContext(),Servis.class));
//progressDialog();
new Servering().execute();
}else{
stopService(new Intent(getApplicationContext(),Servis.class));
}
}
});
}
public void progressDialog(){
/*final ProgressDialog pd = ProgressDialog.show(getApplicationContext(), "lütfen","bekle", true );
pd.setCancelable(false);*/
ProgressDialog pDialog;
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Lütfen Bekleyiniz...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
/*URL obj = new URL("http://85.95.248.115:8014");
URLConnection conn = obj.openConnection();
Map<String, List<String>> map = conn.getHeaderFields();
System.out.println("Printing Response Header...\n");
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey()
+ " ,Value : " + entry.getValue());
}
System.out.println("\nGet Response Header By Key ...\n");
String server = conn.getHeaderField("Server");
if (server == null) {
System.out.println("Key 'Server' is not found!");
} else {
System.out.println("Server - " + server);
}
System.out.println("\n Done");*/
} catch (Exception e) {
e.printStackTrace();
}
pd.dismiss();
}
}).start();
}
@SuppressWarnings("unused")
private class Servering extends AsyncTask<String, String, String>{
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Lütfen Bekleyiniz...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}@Override
protected String doInBackground(String... params) {
checkConnectivity();
//sendBufferCompleteBroadcast();
sendBufferingBroadcast();return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(pDialog!=null){
//sendBufferCompleteBroadcast();
pd.dismiss();
}
}
}
// Handle progress dialogue for buffering...
private void showPD(Intent bufferIntent) {
String bufferValue = bufferIntent.getStringExtra("buffering");
int bufferIntValue = Integer.parseInt(bufferValue);// When the broadcasted "buffering" value is 1, show "Buffering"
// progress dialogue.
// When the broadcasted "buffering" value is 0, dismiss the progress
// dialogue.switch (bufferIntValue) {
case 0:
// Log.v(TAG, "BufferIntValue=0 RemoveBufferDialogue");
// txtBuffer.setText("");
if (pd != null) {
pd.dismiss();
}
break;case 1:
BufferDialogue();
break;// Listen for "2" to reset the button to a play button
case 2:
//buttonPlayStop.setBackgroundResource(R.drawable.playbuttonsm);
break;}
}
// Progress dialogue...
private void BufferDialogue() {if(pd != null){
pd = ProgressDialog.show(MainActivity.this, "Buffering...",
"Acquiring song...", true);
}else{
pd.dismiss();
}
}
// Set up broadcast receiver
private BroadcastReceiver broadcastBufferReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent bufferIntent) {
showPD(bufferIntent);
}
};
@Override
protected void onPause() {
// Unregister broadcast receiver
if (mBufferBroadcastIsRegistered) {
unregisterReceiver(broadcastBufferReceiver);
mBufferBroadcastIsRegistered = false;
}
super.onPause();
}
// -- onResume register broadcast receiver. To improve, retrieve saved screen data ---
@Override
protected void onResume() {
// Register broadcast receiver
if (!mBufferBroadcastIsRegistered) {
registerReceiver(broadcastBufferReceiver, new IntentFilter(
Servis.BROADCAST_BUFFER));
mBufferBroadcastIsRegistered = true;
}
super.onResume();
}
private void checkConnectivity() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);if (cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.isConnectedOrConnecting()
|| cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.isConnectedOrConnecting())
isOnline = true;
else
isOnline = false;
}private void sendBufferingBroadcast() {
// Log.v(TAG, "BufferStartedSent");
bufferIntent.putExtra("buffering", "1");
sendBroadcast(bufferIntent);
}// Send a message to Activity that audio is prepared and ready to start
// playing.
private void sendBufferCompleteBroadcast() {
// Log.v(TAG, "BufferCompleteSent");
bufferIntent.putExtra("buffering", "0");
sendBroadcast(bufferIntent);
}
}
SERVİS :
package com.ndeg;
import java.io.IOException;
import android.app.Service;
import android.content.Intent;
import android.drm.DrmErrorEvent;
import android.drm.DrmManagerClient;
import android.drm.DrmManagerClient.OnErrorListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;public class Servis extends Service {
//46.20.4.43:8110/;stream.mp3
private MediaPlayer player;
//public static final String URL = "";
Intent bufferIntent;
public static final String BROADCAST_BUFFER = "http://85.95.248.115:8014/";
@Override
public void onCreate() {
bufferIntent = new Intent(BROADCAST_BUFFER);
}@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}@Override
public void onDestroy() {
Log.i("onDestroy", "onDestroy");
stopPlaying();
}@Override
@Deprecated
public void onStart(Intent intent, int startId) {
Log.i("onStart", "serviceOnStart");
initializeMediaPlayer();
startPlaying();
}private void initializeMediaPlayer(){
Log.i("initPlayer", "initPlayer");
player = new MediaPlayer();
try {
player.setDataSource("http://85.95.248.115:8014");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.i("Buffering", "" + percent);
}
});
}
private void startPlaying(){
Log.i("startPlaying", "startPlaying");
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
player.start();
sendBufferCompleteBroadcast();
}
});
}
private void stopPlaying(){
Log.i("stopPlaying", "stopPlaying");
if (player.isPlaying()) {
player.stop();
player.release();
initializeMediaPlayer();
}
}
/*public boolean server(){
boolean isOK = false;
try {
URL url = new URL("http://85.95.248.115:8014");
HttpURLConnection urlConnection = null;
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
urlcon.connect();
if (urlcon.getResponseCode() == 200) {
@SuppressWarnings("null")
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String serverStatus = readStream(in); //assuming that "http://yourserverurl/yourstatusmethod" returns OK or ERROR depending on your server status check
isOK = (serverStatus.equalsIgnoreCase("OK"));
}else{
isOK = false;
}//url.disconnect();
} catch (MalformedURLException e1) {
isOK = false;
e1.printStackTrace();
} catch (IOException e) {
isOK = false;
e.printStackTrace();
}
return isOK;
}*/
/*public boolean isConnected() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();if (netInfo != null && netInfo.isConnected()) {
// Network is available but check if we can get access from the
// network.
URL url = new URL("http://85.95.248.115:8014");
HttpURLConnection urlc = (HttpURLConnection) url
.openConnection();
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(2000); // Timeout 2 seconds.
urlc.connect();if (urlc.getResponseCode() == 200) // Successful response.
{
return true;
} else {
Log.d("NO INTERNET", "NO INTERNET");
Toast.makeText(getApplicationContext(), "URL down", Toast.LENGTH_LONG).show();
return false;
}
} else {
Toast.makeText(getApplicationContext(), "No Connection", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}*/
/*private String readStream(InputStream in) {
// TODO Auto-generated method stub
return null;
}*/
// yeni metodlar
private void sendBufferingBroadcast() {
// Log.v(TAG, "BufferStartedSent");
bufferIntent.putExtra("buffering", "1");
sendBroadcast(bufferIntent);
}// Send a message to Activity that audio is prepared and ready to start
// playing.
private void sendBufferCompleteBroadcast() {
// Log.v(TAG, "BufferCompleteSent");
bufferIntent.putExtra("buffering", "0");
sendBroadcast(bufferIntent);
}
//---Error processing ---
public boolean onError(MediaPlayer mp, int what, int extra) {
switch (what) {
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
Toast.makeText(this,
"MEDIA ERROR NOT VALID FOR PROGRESSIVE PLAYBACK " + extra,
Toast.LENGTH_SHORT).show();
break;
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
Toast.makeText(this, "MEDIA ERROR SERVER DIED " + extra,
Toast.LENGTH_SHORT).show();
break;
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
Toast.makeText(this, "MEDIA ERROR UNKNOWN " + extra,
Toast.LENGTH_SHORT).show();
break;
}
return false;
}public void onPrepared(MediaPlayer arg0) {
// Send a message to activity to end progress dialogue
sendBufferCompleteBroadcast();
startPlaying();}
}