2017-08-02 45 views
0

私はアンドロイドの初心者です。 ExoPlayerのビューサーフェスの中心に、Facebookのように再生ボタンと一時停止ボタンの位置を変更したいと思います。ここでは、Exoplayerを使用してMainActivityを作成し、スクロールの目的で3つのtextviewsを作成します。Exoplayerの再生と一時停止のボタンをカスタマイズする

私はbuild.gradle(モジュールのアプリ)に "com.google.android.exoplayer:exoplayer:r2.4.4をコンパイル"

と呼ばれるライブラリを挿入します。それから私はそれを私の activity_mainに使った。以下は私のコードですが、私は親切にもソリューションに感謝します。

activity_main.xmlコード

?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="10dp"> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 

         <LinearLayout 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:orientation="vertical"> 

           <com.google.android.exoplayer2.ui.SimpleExoPlayerView 
            android:layout_width="match_parent" 
            android:layout_height="350dp" 
            android:id="@+id/simple_expo_player"> 

           </com.google.android.exoplayer2.ui.SimpleExoPlayerView> 

         </LinearLayout> 

         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:orientation="vertical"> 

           <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Hello world" 
            android:textAppearance="?android:attr/textAppearanceLarge" /> 

           <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Hello world" 
            android:textAppearance="?android:attr/textAppearanceLarge" /> 

           <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Hello world" 
            android:textAppearance="?android:attr/textAppearanceLarge" /> 


         </LinearLayout> 

         <LinearLayout 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:orientation="vertical"> 


         </LinearLayout> 


       </LinearLayout> 

     </ScrollView> 


</LinearLayout> 

MainActivity.javaコード

package com.example.theace.videoplayer; 


import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import com.google.android.exoplayer2.ExoPlayerFactory; 
import com.google.android.exoplayer2.SimpleExoPlayer; 
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; 
import com.google.android.exoplayer2.extractor.ExtractorsFactory; 
import com.google.android.exoplayer2.source.ExtractorMediaSource; 
import com.google.android.exoplayer2.source.MediaSource; 
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; 
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; 
import com.google.android.exoplayer2.trackselection.TrackSelection; 
import com.google.android.exoplayer2.trackselection.TrackSelector; 
import com.google.android.exoplayer2.ui.SimpleExoPlayerView; 
import com.google.android.exoplayer2.upstream.BandwidthMeter; 
import com.google.android.exoplayer2.upstream.DataSource; 
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; 
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; 
import com.google.android.exoplayer2.util.Util; 

public class MainActivity extends AppCompatActivity { 

    private SimpleExoPlayerView simpleExoPlayerView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     initUi(); 
    } 

    public void initUi(){ 

// 1. Create a default TrackSelector 
     BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); 
     TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); 
     TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); 

// 2. Create the player 

     SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector); 

// 3. Produces DataSource instances through which media data is loaded. 
     DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "com.example.theace.videoplayer")); 
// 4. Produces Extractor instances for parsing the media data. 
     ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); 
// 5. This is the MediaSource representing the media to be played. 
     MediaSource videoSource = new ExtractorMediaSource(Uri.parse("https://www.w3schools.com/html/mov_bbb.mp4"),dataSourceFactory, extractorsFactory, null, null); 

// 6. Prepare the player with the source. 
     player.prepare(videoSource); 
     simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.simple_expo_player); 
     simpleExoPlayerView.setPlayer(player); 

    } 

} 

答えて

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <com.google.android.exoplayer2.ui.SimpleExoPlayerView 
     android:layout_width="match_parent" 
     android:layout_height="350dp" 
     android:id="@+id/simple_expo_player"> 

    </com.google.android.exoplayer2.ui.SimpleExoPlayerView> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:orientation="horizontal"> 
    <Button 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 


     android:gravity="center" 
     android:text="Play"/> 
    <Button 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="Pause"/> 
</LinearLayout> 

</RelativeLayout> 

チェックこの

関連する問題