2017-07-19 11 views
-1

Exoplayerを使用してAndroidアプリケーションでビデオを再生しましたが、結果を表示できません。コードを見ると、この問題で私を助けてくださいExoplayerを使用してAndroidアプリケーションでビデオを再生しましたが、結果を表示できません

私のxmlファイルはvideo.xml

Video.java

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="4dp" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <include layout="@layout/toolbar" /> 
</android.support.design.widget.AppBarLayout> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/nested" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    App: layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:clipToPadding="false" 
      card_view:cardElevation="4dp"> 

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

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:orientation="vertical"> 
         <com.google.android.exoplayer2.ui.SimpleExoPlayerView 
          android:id="@+id/videoView1" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" /> 

        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center_vertical" 
         android:orientation="horizontal" 
         android:padding="@dimen/activity_horizontal_margin"> 

         <LinearLayout 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:gravity="center_vertical" 
          android:orientation="horizontal"> 

         <LinearLayout 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:orientation="vertical" 
        android:paddingStart="@dimen/activity_horizontal_margin"> 

           <TextView 
            android:id="@+id/teacher_name" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="Teacher Name" 
            android:textStyle="bold" /> 

           <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="devalyaonline.com" 
            android:textAppearance="@android:style/TextAppearance.Small" /> 

          </LinearLayout> 

         </LinearLayout> 

        </LinearLayout> 

        <LinearLayout 
         android:layout_width="match_parent" 
         android:layout_height="?attr/actionBarSize" 
         android:background="@color/colorButtonDisabled" 
         android:gravity="center_vertical"> 

         <TextView 
          android:id="@+id/count_comment" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginStart="@dimen/activity_horizontal_margin" 
          android:text="0 comment" 
          android:textAppearance="@android:style/TextAppearance.Medium" /> 
        </LinearLayout> 

        <android.support.v7.widget.RecyclerView 
         android:id="@+id/comment_recycler_view" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:clickable="true" 
         android:scrollbars="vertical" 
         android:stateListAnimator="@android:anim/fade_in" /> 

       </LinearLayout> 
     </android.support.v7.widget.CardView> 

    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

</LinearLayout> 

マイActivityクラスファイル

です

public class Video extends AppCompatActivity { SimpleExoPlayerView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); videoView = (SimpleExoPlayerView) findViewById(R.id.videoView1); CallVideo(); } public void CallVideo() { Intent get_details = getIntent(); final int id = Integer.parseInt(get_details.getStringExtra("id")); final String video_url = get_details.getStringExtra("video_url"); sessionManager = new SessionManager(getApplicationContext()); // Get data from Stored value HashMap<String, String> get_token = sessionManager.getUserDetails(); // Get Token String token = get_token.get(SessionManager.KEY_TOKEN); String username = get_token.get(SessionManager.KEY_FULL_NAME); // 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 final SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector); ApiInterface apiService = ApiClient.createClient(ApiInterface.class); String video_base_Url = "https://api.vimeo.com/videos/" + video_url; final String Video_Token = "Bearer My_Video_Token"; Call<Videos> video_Call = apiService.getVideo(video_base_Url, Video_Token); video_Call.enqueue(new Callback<Videos>() { @Override public void onResponse(Call<Videos> call, Response<Videos> response) { Videos o = response.body(); String uriPath = o.getUri(); Uri videouri = Uri.parse(uriPath); // Bind the player to the view. videoView.setPlayer(player); // Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "DevalyaAndroidApp"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ExtractorMediaSource(videouri, dataSourceFactory, extractorsFactory, null, null); // Prepare the player with the source. player.prepare(videoSource); player.setPlayWhenReady(true); player.release(); } @Override public void onFailure(Call<Videos> call, Throwable t) { } }); } } 

この出力を得ることが

Not showing the video

答えて

0

コードからplayer.release();を削除し、プレーヤーを停止したいときに別の方法に追加します。 player.release();player.setPlayWhenReady(true);の直後に呼び出すと、基本的に動画プレーヤーが停止します。

関連する問題