开发者

Streaming issue in android

I have streamed audio from url,but whe开发者_开发知识库n the call or sms comes i need to pause the song and when the call ends again i am gonna resume the song...

How to do this?...


This method works in my app, it's pretty simple. In your onCreate() put this code to listen for phone events and then act appropriately:

          TelephonyManager telephonyManager;
        PhoneStateListener ringListener;

        // Get the telephony manager
        telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

        // Create a new PhoneStateListener
        ringListener = new PhoneStateListener() {

          @Override
          public void onCallStateChanged(int state, String incomingNumber) {

            String stateString = "none";
            switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
              stateString = "Idle";
              break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
              stateString = "Off Hook";
              break;
            case TelephonyManager.CALL_STATE_RINGING:
              stateString = "Ringing";

            Log.i(TAG, "TELEPHONE RINGING!!");                          

              //Do stuff here when phone ringing detected


            break;
            }
           }
        };

        // Register the listener with the telephony manager
        telephonyManager.listen(ringListener, PhoneStateListener.LISTEN_CALL_STATE);


        //End create a new PhoneStateListener
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜