Home | History | Annotate | Download | only in playback
      1 page.title=PIP
      2 page.keywords=preview, sdk, PIP, Picture-in-picture
      3 page.tags=androidn
      4 
      5 @jd:body
      6 
      7 <div id="tb-wrapper">
      8 <div id="tb">
      9 
     10 <h2>  </h2>
     11 <ol>
     12   <li><a href="#declaring">
     13 PIP  </a></li>
     14   <li><a href="#pip_button"> PIP </a>
     15 </li>
     16   <li><a href="#handling_ui">PIP UI </a>
     17 </li>
     18   <li><a href="#continuing_playback">
     19 PIP   </a></li>
     20   <li><a href="#single_playback">PIP    
     21 </a></li>
     22   <li><a href="#best"> </a></li>
     23 </ol>
     24 
     25 <h2> </h2>
     26 <ol>
     27   <li><a href="{@docRoot}preview/features/multi-window.html"> 
     28 </a></li>
     29 </ol>
     30 
     31 </div>
     32 </div>
     33 
     34 <p>Android N Android TV 
     35        
     36    . PIP(Picture-In-Picture)  
     37     
     38       . PIP       
     39  .</p>
     40 
     41 <p> PIP      . PIP      
     42   .</p>
     43 
     44 <ul>
     45 <li>       
     46  PIP    .</li>
     47 <li>      
     48  PIP    .     
     49     .</li>
     50 <li>    
     51          .       
     52  PIP   .</li>
     53 </ul>
     54 
     55 <p>PIP  240x135dp
     56   4      ,  . 
     57  <b>Home</b>  
     58 PIP     PIP  PIP    .  
     59     PIP 
     60  .  Recents  PIP    .</p>
     61 
     62 <img src="{@docRoot}images/android-7.0/pip-active.png" />
     63 <p class="img-caption"><strong> 1.</strong>      
     64    PIP .
     65 </p>
     66 
     67 <p>PIP Android N      API 
     68     .  PIP 
     69 PIP       PIP   . 
     70  PIP    UI    
     71   .</p>
     72 
     73 <h2 id="declaring"> PIP  </h2>
     74 
     75 <p>    PIP   .
     76  PIP 
     77 <code>android:supportsPictureInPicture</code>
     78 <code>android:resizeableActivity</code> <code>true</code>    
     79 . ,
     80 PIP           
     81      .</p>
     82 
     83 <pre>
     84 &lt;activity android:name="VideoActivity"
     85     android:resizeableActivity="true"
     86     android:supportsPictureInPicture="true"
     87     android:configChanges=
     88         "screenSize|smallestScreenSize|screenLayout|orientation"
     89     ...
     90 </pre>
     91 
     92 <p>   PIP 
     93  TV       .  UI 
     94        .  UI  
     95  PIP   
     96  PIP  UI     
     97       .</p>
     98 
     99 <h2 id="pip_button"> PIP </h2>
    100 
    101  PIP    
    102 <code>Activity.enterPictureInPictureMode()</code> .   
    103     PIP   
    104 PIP  .</p>
    105 
    106 <pre>
    107 &#64;Override
    108 public void onActionClicked(Action action) {
    109     if (action.getId() == R.id.lb_control_picture_in_picture) {
    110         getActivity().enterPictureInPictureMode();
    111         return;
    112     }
    113     ...
    114 </pre>
    115 
    116 <p>   PIP  
    117     PIP     .</p>
    118 
    119 <img src="{@docRoot}images/android-7.0/pip-button.png" />
    120 <p class="img-caption"><strong> 1.</strong>    PIP
    121 .</p>
    122 
    123 <p>Android N   PIP   PIP   
    124 <code>PlaybackControlsRow.PictureInPictureAction</code>   .
    125 </p>
    126 
    127 <h2 id="handling_ui">PIP UI </h2>
    128 
    129 <p> PIP  
    130   .  PIP    UI  
    131         .
    132   <code>Activity.onPictureInPictureModeChanged()</code> 
    133 <code>Fragment.onPictureInPictureModeChanged()</code> 
    134 UI  /.    .</p>
    135 
    136 <pre>
    137 &#64;Override
    138 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
    139     if (isInPictureInPictureMode) {
    140         // Hide the controls in picture-in-picture mode.
    141         ...
    142     } else {
    143         // Restore the playback UI based on the playback status.
    144         ...
    145     }
    146 }
    147 </pre>
    148 
    149 <h2 id="continuing_playback">PIP   
    150 </h2>
    151 
    152 <p> PIP   
    153        <code>onPause()</code>  . 
    154     PIP     
    155   . 
    156 <code>onPause()</code>  PIP    .    .
    157 </p>
    158 
    159 <pre>
    160 &#64;Override
    161 public void onPause() {
    162     // If called while in PIP mode, do not pause playback
    163     if (isInPictureInPictureMode()) {
    164         // Continue playback
    165         ...
    166     }
    167     // If paused but not in PIP, pause playback if necessary
    168     ...
    169 }
    170 </pre>
    171 
    172 <p> PIP     
    173    <code>onResume()</code>  .</p>
    174 
    175 <h2 id="single_playback">PIP    
    176 </h2>
    177 
    178 <p>   PIP   , 
    179           .     
    180     ,    
    181         .</p>
    182 
    183 <p>      
    184   PIP   PIP   ,  
    185 <code>android:launchMode</code> <code>singleTask</code> .
    186 </p>
    187 
    188 <pre>
    189 &lt;activity android:name="VideoActivity"
    190     ...
    191     android:supportsPictureInPicture="true"
    192     android:launchMode="singleTask"
    193     ...
    194 </pre>
    195 
    196 <p> {@link android.app.Activity#onNewIntent
    197 Activity.onNewIntent()}    ,    
    198  .</p>
    199 
    200 <h2 id="best"> </h2>
    201 
    202 <p>PIP     . 
    203 PIP      .
    204 <a href="#handling_ui">PIP UI </a>     PIP   
    205  UI  .</p>
    206 
    207 <p>PIP       
    208 PIP       
    209     .</p>
    210 
    211 <p> PIP       . PIP 
    212   
    213 <code>MediaSession.setMediaButtonReceiver()</code> .</p>
    214