问题
Instead of passing/reading data from json asset file, i am trying to use direct JSON data from api. (i am passing json array data using Intent)
Same content data of json asset is using in api.
is previous code (it read data from JSON asset file)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_chooser_activity);
sampleAdapter = new SampleAdapter();
ExpandableListView sampleListView = findViewById(R.id.sample_list);
sampleListView.setAdapter(sampleAdapter);
sampleListView.setOnChildClickListener(this);
Intent intent = getIntent();
String dataUri = intent.getDataString();
String[] uris;
if (dataUri != null) {
uris = new String[] {dataUri};
} else {
ArrayList<String> uriList = new ArrayList<>();
/*--------Here reading asset json file and add to array list-------*/
AssetManager assetManager = getAssets();
try {
for (String asset : assetManager.list("")) {
if (asset.endsWith(".exolist.json")) {
uriList.add("asset:///" + asset);
}
}
} catch (IOException e) {
Toast.makeText(getApplicationContext(), R.string.sample_list_load_error, Toast.LENGTH_LONG)
.show();
}
uris = new String[uriList.size()];
uriList.toArray(uris);
Arrays.sort(uris);
}
...
}
This is modified code of above, here i am using api json data and pass it to intent.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_chooser_activity);
sampleAdapter = new SampleAdapter();
ExpandableListView sampleListView = findViewById(R.id.sample_list);
sampleListView.setAdapter(sampleAdapter);
sampleListView.setOnChildClickListener(this);
Intent intent = getIntent();
String dataUri = intent.getDataString();
String[] uris;
if (dataUri != null) {
uris = new String[] {dataUri};
} else {
ArrayList<String> uriList = new ArrayList<>();
//Here it pass JSON data------------------
urlvideo = getIntent().getStringExtra("dataVideos");
Log.e("TEST>>>>>>>", urlvideo);
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(urlvideo);
Log.e("TEST>>>>>>> 2222", String.valueOf(jsonArray));
} catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject explrObject = null;
try {
explrObject = jsonArray.getJSONObject(i);
Log.e("TEST>>>>>>> 3333", String.valueOf(explrObject));
} catch (JSONException e) {
e.printStackTrace();
}
uriList.add(String.valueOf(explrObject));
}
uris = new String[uriList.size()];
uriList.toArray(uris);
Arrays.sort(uris);
}
...
}
i am getting these error
2020-04-09 13:25:04.803 2943-3129/com.tamoffline E/SampleChooserActivity: Error loading sample list: {"name":"YouTube DASH","samples":[{"name":"Google Glass (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0","extension":"mpd"},{"name":"Google Play (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=A2716F75795F5D2AF0E88962FFCD10DB79384F29.84308FF04844498CE6FBCE4731507882B8307798&key=ik0","extension":"mpd"},{"name":"Google Glass (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=249B04F79E984D7F86B4D8DB48AE6FAF41C17AB3.7B9F0EC0505E1566E59B8E488E9419F253DDF413&key=ik0","extension":"mpd"},{"name":"Google Play (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=B1C2A74783AC1CC4865EB312D7DD2D48230CC9FD.BD153B9882175F1F94BFE5141A5482313EA38E8D&key=ik0","extension":"mpd"}]}
com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to {"name":"YouTube DASH","samples":[{"name":"Google Glass (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0","extension":"mpd"},{"name":"Google Play (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=A2716F75795F5D2AF0E88962FFCD10DB79384F29.84308FF04844498CE6FBCE4731507882B8307798&key=ik0","extension":"mpd"},{"name":"Google Glass (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=249B04F79E984D7F86B4D8DB48AE6FAF41C17AB3.7B9F0EC0505E1566E59B8E488E9419F253DDF413&key=ik0","extension":"mpd"},{"name":"Google Play (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=B1C2A74783AC1CC4865EB312D7DD2D48230CC9FD.BD153B9882175F1F94BFE5141A5482313EA38E8D&key=ik0","extension":"mpd"}]}
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:282)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:177)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.java:102)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.read(DataSourceInputStream.java:82)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:351)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:180)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at android.util.JsonReader.fillBuffer(JsonReader.java:742)
at android.util.JsonReader.nextNonWhitespace(JsonReader.java:782)
at android.util.JsonReader.nextValue(JsonReader.java:695)
at android.util.JsonReader.peek(JsonReader.java:334)
2020-04-09 13:25:04.806 2943-3129/com.tamoffline E/SampleChooserActivity: at android.util.JsonReader.expect(JsonReader.java:308)
at android.util.JsonReader.beginArray(JsonReader.java:277)
at com.tamoffline.SampleChooserActivity$SampleListLoader.readSampleGroups(SampleChooserActivity.java:293)
at com.tamoffline.SampleChooserActivity$SampleListLoader.doInBackground(SampleChooserActivity.java:276)
at com.tamoffline.SampleChooserActivity$SampleListLoader.doInBackground(SampleChooserActivity.java:261)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.net.MalformedURLException: no protocol: {"name":"YouTube DASH","samples":[{"name":"Google Glass (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0","extension":"mpd"},{"name":"Google Play (MP4,H264)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=A2716F75795F5D2AF0E88962FFCD10DB79384F29.84308FF04844498CE6FBCE4731507882B8307798&key=ik0","extension":"mpd"},{"name":"Google Glass (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/bf5bb2419360daf1\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=249B04F79E984D7F86B4D8DB48AE6FAF41C17AB3.7B9F0EC0505E1566E59B8E488E9419F253DDF413&key=ik0","extension":"mpd"},{"name":"Google Play (WebM,VP9)","uri":"https:\/\/www.youtube.com\/api\/manifest\/dash\/id\/3aa39fa2cc27967f\/source\/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=B1C2A74783AC1CC4865EB312D7DD2D48230CC9FD.BD153B9882175F1F94BFE5141A5482313EA38E8D&key=ik0","extension":"mpd"}]}
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:498)
at java.net.URL.<init>(URL.java:447)
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:429)
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:280)
... 22 more
This is the sample data i am passing in Intent.
[
{
"name": "YouTube DASH",
"samples": [
{
"name": "Google Glass (MP4,H264)",
"uri": "https://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0",
"extension": "mpd"
},
{
"name": "Google Play (MP4,H264)",
"uri": "https://www.youtube.com/api/manifest/dash/id/3aa39fa2cc27967f/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=A2716F75795F5D2AF0E88962FFCD10DB79384F29.84308FF04844498CE6FBCE4731507882B8307798&key=ik0",
"extension": "mpd"
},
{
"name": "Google Glass (WebM,VP9)",
"uri": "https://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=249B04F79E984D7F86B4D8DB48AE6FAF41C17AB3.7B9F0EC0505E1566E59B8E488E9419F253DDF413&key=ik0",
"extension": "mpd"
},
{
"name": "Google Play (WebM,VP9)",
"uri": "https://www.youtube.com/api/manifest/dash/id/3aa39fa2cc27967f/source/youtube?as=fmp4_audio_clear,webm2_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=B1C2A74783AC1CC4865EB312D7DD2D48230CC9FD.BD153B9882175F1F94BFE5141A5482313EA38E8D&key=ik0",
"extension": "mpd"
}
]
}
]
来源:https://stackoverflow.com/questions/61116864/what-cause-java-net-malformedurlexception-no-protocol-when-trying-to-replace-j