Android和Django-使用Android的ExoPlayer作为客户端时出现ConnectionResetError

问题描述

我创建了一个小小的Android App,它会使用ExoPlayer用户显示一些视频文件(.mp4)。 .mp4文件均从我的笔记本电脑Django上的本地开发服务器获取。具体来说,我使用Django Rest Framework创建了一个小小的客户端-服务器关系,以便可以交换文件

用户选择视频时,ExoPlayer负责播放视频。其背后的逻辑是:

// called from onResume()
private fun initializeMainVideoPlayer(){
   // initialize our SimpleExoPlayer instance as usual 
   mainVideoplayer = ExoPlayerFactory.newSimpleInstance(context)
   
   // assign the player to the corresponding UI widget (com.google.android.exoplayer2.ui.PlayerView)
   binding.detailedplayerView.player = mainVideoplayer
   
   // get the url of the file from navArgs passed to the fragment
   val uri: Uri = Uri.parse(args.fileUrl)
   // use the Uri of the url to create a MediaSource 
   val mediaSource : MediaSource = buildMediaSource(uri)

   // set some properties of the player & prepare it for playing 
   mainVideoplayer?.apply {
        playWhenReady = true                        // play automatically
        repeatMode = Player.REPEAT_MODE_ONE         // let it loop endlessly
        prepare(mediaSource,false,false)
   }
}

// creates the MediaSource object used for the prepare() call
private fun buildMediaSource(uri: Uri): MediaSource =
       ProgressiveMediaSource.Factory(DefaultDataSourceFactory(context,"exoplayer")).createMediaSource(uri)

我认为这是非常基本的。现在,一旦应用程序获取文件数据,视频就会开始播放(请注意playWhenReady = true),并在我的命令行上,我可以观察到很多GET requests到本地服务器,然后是ConnectionResetError,如下所示:

[04/Sep/2020 14:43:40] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 266240
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 138,in run
    self.finish_response()
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 180,in finish_response
    self.write(data)
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 279,in write
    self._write(data)
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 453,in _write
    result = self.stdout.write(data)
  File "/usr/lib/python3.6/socketserver.py",line 803,in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
[04/Sep/2020 14:43:40] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('192.168.2.102',37610)
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 141,in run
    self.handle_error()
  File "/home/ac3l1k/Desktop/PROJECT/myLittleProject/env/lib/python3.6/site-packages/django/core/servers/basehttp.py",line 119,in handle_error
    super().handle_error()
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 368,in handle_error
    self.finish_response()
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 274,in write
    self.send_headers()
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 331,in send_headers
    if not self.origin_server or self.client_is_modern():
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 344,in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'nonetype' object is not subscriptable

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py",line 654,in process_request_thread
    self.finish_request(request,client_address)
  File "/usr/lib/python3.6/socketserver.py",line 364,in finish_request
    self.RequestHandlerClass(request,client_address,self)
  File "/usr/lib/python3.6/socketserver.py",line 724,in __init__
    self.handle()
  File "/home/ac3l1k/Desktop/PROJECT/myLittleProject/env/lib/python3.6/site-packages/django/core/servers/basehttp.py",line 172,in handle
    self.handle_one_request()
  File "/home/ac3l1k/Desktop/PROJECT/myLittleProject/env/lib/python3.6/site-packages/django/core/servers/basehttp.py",line 197,in handle_one_request
    handler.run(self.server.get_app())
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 144,in run
    self.close()
  File "/home/ac3l1k/Desktop/PROJECT/myLittleProject/env/lib/python3.6/site-packages/django/core/servers/basehttp.py",line 114,in close
    super().close()
  File "/usr/lib/python3.6/wsgiref/simple_server.py",line 35,in close
    self.status.split(' ',1)[0],self.bytes_sent
AttributeError: 'nonetype' object has no attribute 'split'
----------------------------------------
[04/Sep/2020 14:43:43] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 4030034
[04/Sep/2020 14:43:44] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 4030034
[04/Sep/2020 14:43:45] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 376832
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
[04/Sep/2020 14:43:45] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('192.168.2.102',37616)
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",line 174,self.bytes_sent
AttributeError: 'nonetype' object has no attribute 'split'
----------------------------------------
[04/Sep/2020 14:43:46] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 4030034
[04/Sep/2020 14:43:48] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 4030034
[04/Sep/2020 14:43:48] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 200 409600
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py",in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
[04/Sep/2020 14:43:48] "GET /media/Videos/2020-09-01-12-43-16-345.mp4 HTTP/1.1" 500 59
// I skipped a lot because the pattern is always the same: a bunch of GET requests followed by ConnectionResetError and so on 

有人可以帮助我解决我的问题吗?仅当我播放视频时才会发生这种服务器错误。其他API接口不会导致此类错误At this SO thread,他们说这是在服务器端发生的,并且向服务器发出了太多请求。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...