如何暂停和播放使用 RTP 传输的 J2ME 音频播放器
以下是我尝试通过 RTP 播放来自服务器的音频流的方法。
try {
String url = "rtp://...";
Player p = Manager.createPlayer(url);
p.realize();
VideoControl video = (VideoControl) p.getControl("VideoControl");
Item itm = (Item) video.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
midlet.form.append(itm);
p.start();
} catch (Exception e) {...}
我尝试了http,效果很好。在http中,所有媒体内容都下载下来,然后我们可以播放、暂停和再次播放。没关系。我想从 RTP 播放音频。我想知道如何在用户需要播放时暂停播放器(并且不下载数据,在媒体暂停的位置保留记录)再次播放(并从最后下载的点再次开始下载(而不是从头开始))。
据我所知,智能手机无法与服务器保持会话,因为每次向服务器发送请求时,手机不会保持会话并发送回服务器(而只是发送请求并获取响应,无会话管理)。也许我错了。
无论如何,如何在 J2ME 应用程序中暂停(并停止下载)并再次播放(从下载停止的最后一点开始下载)音频?如果有人知道好的解决方案、示例代码,请告诉我。
Here is how I try to play an audio streaming from a server over RTP.
try {
String url = "rtp://...";
Player p = Manager.createPlayer(url);
p.realize();
VideoControl video = (VideoControl) p.getControl("VideoControl");
Item itm = (Item) video.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
midlet.form.append(itm);
p.start();
} catch (Exception e) {...}
I tried http and it worked well. In http, all the media content download and then we can play, pause and play again. It is ok. I want to play an audio from RTP. I want to know how to pause the player (and data is not downloading, keep a record where the media paused) again play when user needs to play (and start downloading again from the last point downloaded (not from beginning)).
As far as I know, smartphones cannot keep a session with the server as the mobile phone doesn't keep sessions and send back to the server every time a request is sent to the server (and just only send a request and get the response, no session management). Maybe I am wrong.
Anyway how can I pause (and stop downloading) and play again (start downloading from the last point where downloading stopped) an audio in a J2ME application? Please let me know if any one know a good solution, sample code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
流式传输时,不会立即下载整个媒体,而是在播放过程中下载部分媒体。当使用 rtp/rtsp 定位器创建播放器时,调用 player.stop() 足以停止播放和任何进一步的媒体下载。同样,player.start() 足以从停止的位置恢复播放。
您必须记住,由于媒体不是本地的,如果流在一段时间后没有恢复,流服务器可能会认为流已超时,您需要重新建立流。
When streaming, the entire media is NOT downloaded at once,rather portions of the media are downloaded as playback progresses. When a player is created with rtp/rtsp locator, calling player.stop() is enough to stop playback and any further download of the media.Likewise, player.start() is enough to resume playback from where it was stopped.
You must bear in mind that since the media is not local if a stream is not resumed after a while the streaming server may consider a stream to have timed out and you would need reestablish the stream.
只需遵循player.stop(),player.start();功能足够
Just follow player.stop(),player.start(); function enough