The previous article on the Android on the use of PHONEGAP development play HLS solution, in fact, the best solution is to develop their own player for HLS video, but the development of the player is a vast project, must be familiar with the native Android development, and video playback knowledge needs a certain accumulation. This is obviously unrealistic for general developers, especially web developers, and it goes against our intention to use PHONEGAP to develop cross-platform mobile software. So how do we achieve our expected goals in this situation? The answer is to call a third-party app.
Step1: First, you need to install a player on your phone that can play the HLS protocol video, such as Mxplayer or QQ browser.
Step2: How to call this player to play it? Involves invoking the player this is going to write the native Java code, we can use this Videoplayer phonegap plugin https://github.com/raulduran/VideoPlayer, directly use this plugin to play video, It is different on different mobile phones, the author uses the red rice mobile phone to test. Playing directly will call the system comes with the player to play, in this case, this player is not able to play HLS video. And red rice phone can not change the default video player (not root), how to solve?
Step3: Of course, we can get the package name of the third-party player installed on the phone and the entry activity class name to open it directly, but this method needs to write a lot of code, and inefficient, because to find all the apps on the phone.
Step4: The best way is to modify the source code of the Videoplayer plug-in we use, since the index file of HLS video is based on TS extension, we
Modify the following code in Videoplayer.java The original is Intent.setdataandtype (URI, "video/*"), now instead of Intent.setdataandtype (URI, "Video/ts"), then click the Play button, will produce the following effect At this time select the default video player, and choose the default to remember this, then the next play will call this player directly to play.