title: Chromcast Remoteplayer seek to resume at seek 0 position when using nanohttpd
body: <p>Chromcast Remote player seek to resume at seek position 0  when using nanohttpd server. Main issue getting when I seek  into video player in device its working fine but on TV seek-bar set at 0 position and music stat at beginning. </p>
  
  <p>When to call mRemoteMediaPlayer.seek() in onSeekChanged() getting result success but on TV seek-bar set at 0 position and music stat at beginning. </p>
  
  <pre><code>public class webserver extends NanoHTTPD {  
          FileInputStream fileInputStream;
          public webserver(){
                  super(8080);
          }
          @Override
          public Response serve(String uri, Method method, Map&lt;String, String&gt; header,Map&lt;String, String&gt; parameters, Map&lt;String, String&gt; files) {
            String mediasend=" ";
              long size=0;
            FileInputStream fis = null;
            try { 
                   fis = new FileInputStream(path);
                //byte[] buffer =   new byte[(int) fis.getChannel().size()];
                size=fis.getChannel().size();
  
            } catch (Exception e) {
                      e.printStackTrace();
          }
  
  
          switch(mediatype){
            case "photo":
               mediasend="image/jpeg";
               break;
            case "audio":
               mediasend="audio/mp3";
               break;
            case "video":
               mediasend="video/mp4"; 
               break;
          }
  
          return new NanoHTTPD.Response(com.castoffline.castActivity.NanoHTTPD.Response.Status.OK,mediasend,fis,size);
         }   
      }
  </code></pre>
  
  <p><strong>Cast connection code</strong> </p>
  
  <pre><code>Cast.CastApi.launchApplication(mApiClient,getString(R.string.app_id),false).setResultCallback(new ResultCallback&lt;Cast.ApplicationConnectionResult&gt;() {
                      @Override
                      public void onResult(ApplicationConnectionResult result) {
                      Status status = result.getStatus();
                      if (status.isSuccess()) {
                          ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
                          mSessionId = result.getSessionId();
                          String applicationStatus = result.getApplicationStatus();
                          boolean wasLaunched = result.getWasLaunched();
                          Log.d(TAG,"application name: "+ applicationMetadata.getName()+ ", status: "+ applicationStatus+ ", sessionId: "+ mSessionId+ ", wasLaunched: "+ wasLaunched);
                          mApplicationStarted = true;
                          mRemoteMediaPlayer = new RemoteMediaPlayer();
                          /*
                           * Identify the mediatype and send the metadata details to media info       
                           */
                          switch(mediatype)   
                          {   
                              case "audio" :  mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
                                              mediaMetadata.putString(MediaMetadata.KEY_TITLE, "MY MUSIC TRACK"+":  "+audioTitle);
                                              mediaMetadata.putString(MediaMetadata.KEY_ARTIST,audioArtist);
                                              mediaMetadata.addImage(new WebImage(Uri.parse("https://www.googledrive.com/host/0B61ekPEN_94sZ21mcnQtbVU2RHM/media.png")));
                                              mediaInfo = new MediaInfo.Builder(ipdevice).setContentType(mimetype).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).build();
                              break;
                              case "video" :  mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
                                              mediaMetadata.addImage(new WebImage(Uri.parse("https://www.googledrive.com/host/0B61ekPEN_94sZ21mcnQtbVU2RHM/film_reel.png")));
                                              mediaMetadata.putString(MediaMetadata.KEY_TITLE, "My MOVIE"+":  "+videoTitle);
                                              mediaInfo = new MediaInfo.Builder(ipdevice).setContentType(mimetype).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).build();
                              break;
                              case "photo" :  mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO);
                                              mediaMetadata.putString(MediaMetadata.KEY_TITLE, "My PHOTO"+":  ");
                                              mediaInfo = new MediaInfo.Builder(ipdevice).setContentType(mimetype).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).build();
                              break;
                              default:
                           }
                          try {
                                  Cast.CastApi.setMessageReceivedCallbacks(mApiClient,mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
                               } catch (IOException e) {
                                                  Log.d(TAG, "Exception while creating media channel", e);
                               }
                          try {
  
                                  mRemoteMediaPlayer.load(mApiClient, mediaInfo, false,0).setResultCallback(new ResultCallback&lt;RemoteMediaPlayer.MediaChannelResult&gt;() {
                                  @Override
                                  public void onResult(MediaChannelResult result) {
                                      if (result.getStatus().isSuccess()) {
                                                          Log.d(TAG, "Media loaded successfully");
                                      }
                                  }});
                                  /*
                                   * checks if the video is playing or if it is paused and according it will be played/paused in the receiver
                                   */
                                  videoview.setPlayPauseListener(new CustomVideoView.PlayPauseListener() {
                                  AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
                                  @Override
                                  public void onPlay() {
                                      playbackPaused=false;  //videoView is playing
                                      if(mSelectedDevice!=null &amp;&amp; mApiClient != null &amp;&amp; mRemoteMediaPlayer != null){
                                          //volume is set to mute if media is casting in Chromecast
                                          amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
                                          sendMediaControl(playbackPaused,false);
                                      }else{
                                               amanager.setStreamVolume(AudioManager.STREAM_MUSIC, 3,1);
                                            }
  
                                   }
                                   @Override
                                   public void onPause(){
                                      playbackPaused=true; //videoView is paused
                                      if (mSelectedDevice != null &amp;&amp; mApiClient != null &amp;&amp; mRemoteMediaPlayer != null){
                                          amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
                                          sendMediaControl(playbackPaused,false);
                                      }else{
                                          amanager.setStreamVolume(AudioManager.STREAM_MUSIC, 3,1); }
                                   }
                                   /* Currently Seek function is not working for the media playback while casting
                                    * (non-Javadoc)
                                    * @see com.castoffline.castActivity.CustomVideoView.PlayPauseListener#onSeekChanged(int)
                                    */
  
  
                                  @Override
                                   public void onSeekChanged(int pos){
                                       Log.d(String.valueOf(videoview.getCurrentPosition()),"seekinsie");
                                      // seek(videoview.getCurrentPosition());
  
                                      Log.d("mimetype ",mimetype);
  
                                      Log.d("seek1",""+pos);
  
                                      if (mSelectedDevice != null &amp;&amp; mApiClient != null &amp;&amp; mRemoteMediaPlayer != null){
  
                                          videoview.pause();
                                          final long position=videoview.getCurrentPosition();
                                          Log.d("seek",""+position);
  
  
                                          mRemoteMediaPlayer.seek(mApiClient,position,RemoteMediaPlayer.RESUME_STATE_UNCHANGED).setResultCallback(new ResultCallback&lt;RemoteMediaPlayer.MediaChannelResult&gt;(){
                                              @Override
                                              public void onResult(MediaChannelResult result) {
                                                  if (result.getStatus().isSuccess()) {
                                                      Log.d(String.valueOf("State Code "+result.getStatus().getStatusCode()),""+mRemoteMediaPlayer.getApproximateStreamPosition());
  
                                                  }
                                              }
                                          });
                                          mRemoteMediaPlayer.setOnStatusUpdatedListener(new RemoteMediaPlayer.OnStatusUpdatedListener(){
                                              @Override
                                              public void onStatusUpdated() {
                                                  @SuppressWarnings("unused")
                                                  MediaStatus mediaStatus = mRemoteMediaPlayer.getMediaStatus();
                                                  Log.d("seek state update",""+mediaStatus);
  
                                              }
                                          });
                                      }
  
  
                                  }
                               });
                          } catch (IllegalStateException e) {
                                  Log.d(TAG, "Problem occurred with media during loading", e);
                  } catch (Exception e) {
                                  Log.d(TAG, "Problem opening media during loading", e);}
          } else {
                      Log.e(TAG,"application could not launch");
                      teardown();
                  }
      }
  });
  }
  </code></pre>
  
  <p><strong>Remote player control code.</strong></p>
  
  <pre><code>private void sendMediaControl(final boolean playbackPaused,final boolean change)
  {
      if (mApiClient != null &amp;&amp; mRemoteMediaPlayer != null){
          mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback( new ResultCallback&lt;RemoteMediaPlayer.MediaChannelResult&gt;() {
          @Override 
          public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) {
  
                  if(playbackPaused ==true){
                      mRemoteMediaPlayer.pause(mApiClient);
                  }else{
                      mRemoteMediaPlayer.play(mApiClient);
  
                  }               
          }
      });
      }
  }
  </code></pre>