Установить заголовки на Android Vitamio
Я пытаюсь воспроизвести потоковый HLS (m3u8), который требует некоторые параметры, такие как User-Agent и Referer, но не работает.
Мой код:
...
Map<String,String> options = new HashMap<>();
options.put("Referer","Xxxxxxxx");
options.put("User-Agent","Yyyyyyyy");
videoView.setVideoURI(streamURI,options);
...
И ответ:
D/Vitamio[5.0.1][Player]: [http @ 0x9627e500] HTTP error 403 Forbidden
E/Vitamio[5.0.1][Player]: avformat_open_input: Server returned 403 Forbidden (access denied) : -858797304
Также я попытался использовать это так:
options.put("headers","Referer:Xxxxxxxx\r\n");
options.put("headers","User-Agent:Yyyyyyyy\r\n");
Результат был таким же...
Есть ли ошибка в коде? Формат? заказ может быть?
Благодарю.
1 ответ
Решение
final HashMap<String, String> options;
options = new HashMap<>();
options.put("headers", "User-Agent: myUserAgent\r\n");
videoView.setVideoURI(Uri.parse("http://www.example.com/playlist.m3u8), options);
Это правильный метод. Но разбор User Agent отличается от стандартного метода. Какой сервер вы используете?