我正在开发一个应用程序,以显示youtube播放列表中的视频列表,并且我的应用程序在cardview中具有一个共享按钮,当按下该按钮时,该视频将被下载到手机中,而实际的视频将被共享给某人
我尝试在RecyclerView适配器中使用YoutbeExtractor,但没有得到 如何使用该库以及在程序中的使用位置。
public class MainActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private VideoAdapter mVideoAdapter;
private RequestQueue mRequestQueue;
private ArrayList<Videos> mVideoList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Error here
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager (new LinearLayoutManager(this));
mVideoList = new ArrayList<>();
mRequestQueue = Volley.newRequestQueue(this);
parseJson();
}
private void parseJson() {
String url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=PLrnPJCHvNZuBCiCxN8JPFI57Zhr5SusRL&key=AIzaSyCEynSidiZ7QOucFLLWiq--IMDRTmMOzL0";
final JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("items");
for(int i = 0; i<jsonArray.length(); i++){
JSONObject items = jsonArray.getJSONObject(i);
JSONObject snip = items.getJSONObject("snippet");
JSONObject ThumbNail = snip.getJSONObject("thumbnails");
JSONObject def = ThumbNail.getJSONObject("medium");
JSONObject resId = snip.getJSONObject("resourceId");
String title = snip.getString("title");
String thumbnailUrl = def.getString("url");
String VideoId = resId.getString("videoId");
String YoutubeUrl = "youtube.com/watch?v=" + VideoId;
mVideoList.add(new Videos(thumbnailUrl,title,VideoId));
}
mVideoAdapter = new VideoAdapter(MainActivity.this,mVideoList);
mRecyclerView.setAdapter(mVideoAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("RES", String.valueOf(response));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mRequestQueue.add(request);
}
}