forked from CarGuo/GSYVideoPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/example/gsyvideoplayer/FragmentVideoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.gsyvideoplayer; | ||
|
||
import android.os.Build; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.transition.Explode; | ||
import android.view.Window; | ||
|
||
import com.example.gsyvideoplayer.fragment.VideoFragment; | ||
|
||
public class FragmentVideoActivity extends AppCompatActivity { | ||
VideoFragment newFragment; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
// 设置一个exit transition | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); | ||
getWindow().setEnterTransition(new Explode()); | ||
getWindow().setExitTransition(new Explode()); | ||
} | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fragment); | ||
|
||
newFragment = new VideoFragment(); | ||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); | ||
transaction.replace(R.id.frameLayout, newFragment); | ||
transaction.addToBackStack(null); | ||
transaction.commit(); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
if (newFragment.onBackPressed()) { | ||
return; | ||
} | ||
finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
app/src/main/java/com/example/gsyvideoplayer/fragment/VideoFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package com.example.gsyvideoplayer.fragment; | ||
|
||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.transition.Explode; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.Window; | ||
|
||
import com.example.gsyvideoplayer.R; | ||
import com.example.gsyvideoplayer.adapter.ListNormalAdapter; | ||
import com.example.gsyvideoplayer.adapter.RecyclerBaseAdapter; | ||
import com.example.gsyvideoplayer.adapter.RecyclerNormalAdapter; | ||
import com.example.gsyvideoplayer.holder.RecyclerItemNormalHolder; | ||
import com.example.gsyvideoplayer.model.VideoModel; | ||
import com.shuyu.gsyvideoplayer.GSYVideoManager; | ||
import com.shuyu.gsyvideoplayer.GSYVideoPlayer; | ||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
|
||
public class VideoFragment extends Fragment { | ||
|
||
|
||
@BindView(R.id.list_item_recycler) | ||
RecyclerView videoList; | ||
|
||
LinearLayoutManager linearLayoutManager; | ||
|
||
RecyclerBaseAdapter recyclerBaseAdapter; | ||
|
||
List<VideoModel> dataList = new ArrayList<>(); | ||
|
||
public VideoFragment() { | ||
// Required empty public constructor | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
// Inflate the layout for this fragment | ||
View view = inflater.inflate(R.layout.fragment_video, container, false); | ||
|
||
ButterKnife.bind(this, view); | ||
|
||
resolveData(); | ||
|
||
final RecyclerNormalAdapter recyclerNormalAdapter = new RecyclerNormalAdapter(getActivity(), dataList); | ||
linearLayoutManager = new LinearLayoutManager(getActivity()); | ||
videoList.setLayoutManager(linearLayoutManager); | ||
videoList.setAdapter(recyclerNormalAdapter); | ||
|
||
videoList.addOnScrollListener(new RecyclerView.OnScrollListener() { | ||
|
||
int firstVisibleItem, lastVisibleItem; | ||
|
||
@Override | ||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | ||
super.onScrollStateChanged(recyclerView, newState); | ||
} | ||
|
||
@Override | ||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | ||
super.onScrolled(recyclerView, dx, dy); | ||
firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition(); | ||
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); | ||
//大于0说明有播放 | ||
if (GSYVideoManager.instance().getPlayPosition() >= 0) { | ||
//当前播放的位置 | ||
int position = GSYVideoManager.instance().getPlayPosition(); | ||
//对应的播放列表TAG | ||
if (GSYVideoManager.instance().getPlayTag().equals(RecyclerItemNormalHolder.TAG) | ||
&& (position < firstVisibleItem || position > lastVisibleItem)) { | ||
|
||
//如果滑出去了上面和下面就是否,和今日头条一样 | ||
GSYVideoPlayer.releaseAllVideos(); | ||
recyclerNormalAdapter.notifyDataSetChanged(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return view; | ||
} | ||
|
||
public boolean onBackPressed() { | ||
if (StandardGSYVideoPlayer.backFromWindowFull(getActivity())) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
GSYVideoManager.onPause(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
GSYVideoManager.onResume(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
GSYVideoPlayer.releaseAllVideos(); | ||
} | ||
|
||
|
||
private void resolveData() { | ||
for (int i = 0; i < 19; i++) { | ||
VideoModel videoModel = new VideoModel(); | ||
dataList.add(videoModel); | ||
} | ||
if (recyclerBaseAdapter != null) | ||
recyclerBaseAdapter.notifyDataSetChanged(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/primary_material_dark"> | ||
|
||
<FrameLayout | ||
android:id="@+id/frameLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/activity_recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/list_item_recycler" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters