2015-07-27 1 views
5

Я пошел на сайт Samsung и загрузил пакет SDK Media Control. Когда я использовал AllShare Cast Video Player на своей Galaxy S3 Android 4.3, мой Smart TV (в той же сети) появился в списке AllShare Cast.AllShare Cast/Screen Не работает на некоторых телефонах

Однако

Когда я использовал тот же приложение на моем Galaxy Note корневого 2 Android 4.1.1, мой Smart TV (в одной и той же сети) не появлялся на Каст списке AllShare.

Код:

public class DevicePicker extends Fragment implements OnClickListener,SmcDeviceFinder.StatusListener, SmcDeviceFinder.DeviceListener { 


    public interface DevicePickerResult { 

     void onDeviceSelected(SmcDevice device); 

     /** 
     * User clicked to disable AllShare 
     */ 
     void onAllShareDisabled(); 
    } 

    /** 
    * The type of device we are interested in 
    */ 
    private int mType = SmcDevice.TYPE_AVPLAYER; 

    /** 
    * Listener to be notified of events 
    */ 
    private DevicePickerResult mPickerListener; 

    /** 
    * Device finder instance 
    */ 
    private SmcDeviceFinder smcDeviceFinder; 

    /** 
    * The ImageView displaying AllShare icon 
    */ 
    private ImageView mIcon; 

    /** 
    * Flag indicating if AllShare is currently active 
    */ 
    private boolean mActive; 

    private String mDeviceId; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     // Set view, remember ImageView for icon and setup onclick listener. 
     View v = inflater.inflate(R.layout.device_picker, container, false); 
     mIcon = (ImageView) v.findViewById(R.id.devicePickerIcon); 
     mIcon.setOnClickListener(this); 
     return v; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     /* 
     if(savedInstanceState!=null){ 
      mDeviceId = savedInstanceState.getString("deviceId"); 
     } 
     */ 
    } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 

    } 

    public void setDeviceType(int type) { 
     mType = type; 
    } 

    public void setDeviceSelectedListener(DevicePickerResult listener) { 
     mPickerListener = listener; 
     restoreDevice(); 
    } 

    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     // The service provider needs to be created after device type is set 
     // It could also be created in onStart or onResume, but we the sooner 
     // we create it, the sooner we get devices. 
     SmcDeviceFinder df = new SmcDeviceFinder(getActivity()); 
     df.setStatusListener(this); 
     df.start(); 

    } 


    private void restoreDevice(){ 
     if(smcDeviceFinder != null && mDeviceId!=null && mPickerListener != null) { 
      SmcDevice SmcDevice_ = smcDeviceFinder.getDevice(mType, mDeviceId); 
      if(SmcDevice_!=null){ 
       mPickerListener.onDeviceSelected(SmcDevice_); 
       setActive(true); 
      } 
     } 
    } 

    public void setActive(boolean newState) { 
     if (newState == mActive) { 
      // No change in state, do nothing 
      return; 
     } 
     mActive = newState; 
     mIcon.setImageResource(
       newState ? 
         R.drawable.allshare_icons_active : 
         R.drawable.allshare_icons_inactive); 
     updateButtonCounter(); 
    } 

    @Override 
    public void onClick(View v) { 
     if (v != mIcon) { 
      return; 
     } 

     if(smcDeviceFinder != null) { 

      int numDevices = smcDeviceFinder.getDeviceList(mType).size(); 

      // If no devices found, try refreshing the list. 
      if (numDevices == 0) { 
       smcDeviceFinder.rescan(); 
      } 

      // If we are already active, disable allshare 
      if (mActive) { 
       setActive(false); 
       if (mPickerListener != null) { 
        mPickerListener.onAllShareDisabled(); 
       } 
       return; 
      } 
     } 

     // Devices are available, and we are not connected 
     // Ask user to select device 
     showPickerDialog(); 
    } 

    @Override 
    public void onDetach() { 
     if (smcDeviceFinder != null) { 
      smcDeviceFinder.stop(); 
      smcDeviceFinder = null; 
     } 
     super.onDetach(); 
    } 

    /////////////////////////////////////////////////////////////////////////// 
    // These methods handle device finder start hide event. 
    /////////////////////////////////////////////////////////////////////////// 

    @Override 
    public void onStarted(SmcDeviceFinder deviceFinder, int error) { 
     if (error == Smc.SUCCESS) { 
      smcDeviceFinder = deviceFinder; 
      smcDeviceFinder.setDeviceListener(mType, this); 
      smcDeviceFinder.rescan(); 
      updateButtonCounter(); 
      restoreDevice(); 
     } 
    } 

    @Override 
    public void onStopped(SmcDeviceFinder deviceFinder) { 
     if (smcDeviceFinder == deviceFinder) { 
      smcDeviceFinder.setDeviceListener(mType, null); 
      smcDeviceFinder.setStatusListener(null); 
      smcDeviceFinder = null; 
     } 
    } 

    /////////////////////////////////////////////////////////////////////////// 
    // These methods handle devices appearing and disappearing in network. 
    /////////////////////////////////////////////////////////////////////////// 

    @Override 
    public void onDeviceAdded(SmcDeviceFinder deviceFinder, SmcDevice smcDevice) { 
     // We aren't interested in individual devices, only in their number 
     updateButtonCounter(); 
    } 

    @Override 
    public void onDeviceRemoved(SmcDeviceFinder deviceFinder, SmcDevice smcDevice, int error) { 
     // We aren't interested in individual devices, only in their number 
     updateButtonCounter(); 
     //if current device has been removed 
     if (smcDevice.getId().equals(mDeviceId)) { 
      setActive(false); 
      if (mPickerListener != null) { 
       mPickerListener.onAllShareDisabled(); 
      } 
     } 
    } 



    /** 
    * Methods that selects which icon to display, based on number of 
    * available devices in network. 
    */ 
    private void updateButtonCounter() { 
     if (smcDeviceFinder != null) { 
      int numDevices = 
       smcDeviceFinder.getDeviceList(mType).size(); 

      mIcon.getDrawable().setLevel(numDevices); 
      if (numDevices==0) { 
       setActive(false); 
      } 
     } 
    } 

    public void showPickerDialog() { 
     Intent intent = new Intent(getActivity(), DeviceSelectActivity.class); 
     intent.putExtra("deviceType", mType); 
     startActivityForResult(intent, 0); 
    } 

    /** 
    * Callback when user has selected device in device select activity. 
    */ 
    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode == Activity.RESULT_OK) { 
      mDeviceId = data.getStringExtra("deviceId"); 
      int type = data.getIntExtra("deviceType", -1); 

      if (smcDeviceFinder != null && mPickerListener != null) { 
       SmcDevice device = smcDeviceFinder.getDevice(type, mDeviceId); 
       if(device!=null){ 
        mPickerListener.onDeviceSelected(device); 
        setActive(true); 
       } 
      } 
     } 
    } 
} 

WiFi был включен.

Может кто-нибудь, пожалуйста, помогите мне?

Есть приложения, которые даже могут видеть мой телевизор устройство Apple (мое приложение не может даже посмотреть телевизор устройства Apple, на Кастах списка AllShare)

Большого спасибо.

ответ

0

Если я не ошибаюсь, кастинг AllShare построен поверх Miracast. Эта функция была включена в Android 4.2 для устройств с необходимой аппаратной поддержкой, что объясняет, почему в вашей версии Note 2 4.1.1 есть проблемы.

+0

Спасибо за комментарии, но это не так. Их сайт говорит: «Устройства с Android 4.0 Ice Cream Sandwich (API уровня 14) или выше» Ссылка: http://developer.samsung.com/galaxy#media-control благодарит много –

+0

Теперь, когда вы упомянули об этом, я думаю, что поддержка Miracast был добавлен в ключ/устройство AllShare через обновление программного обеспечения. Действительно ли Samsung действительно не обновил примечание 2 за 4.1.1? – blunden

+0

Я понятия не имею, спасибо –