视屏快进快退按小片段进行

视屏按照后台下发的模块(片段节点)快进或快退

protected void prev() {
        isFastSeeking = true;
        if (isLoopSegmeng) {
            isLoopSegmeng = false;
            playMenuView.setPlayLoopSegmengBackgroud(isLoopSegmeng);
        }
        int position = playEngine.getPosition();

        if (list != null && list.size() > 0) {


            for (int i = 0; i < list.size(); i++) {
                SquareDanceModel m = list.get(i);
                {
                    if (position <= (m.getEnd() * 1000) && position >= (m.getStart() * 1000)) {
                        playSegmengIndex--;

                        if (playSegmengIndex < 0) {
                            playSegmengIndex = 0;
                        }

                        playEngine.seekPlay(list.get(playSegmengIndex).getStart() * 1000);
                        isSwitchNext = 1;
                    }
                }
            }
        }
//        int position = playEngine.getPlayer().getPosition() - onceSpeedLength;
//        int position;
//        //TODO posion 获取seekbar当前进度
//        position = playMenuView.getPlayProcess() - onceSpeedLength;
//        playMenuView.onPlayProcess(position);
//        handler.removeCallbacks(mSeekListenerRunnable);
//        handler.postDelayed(mSeekListenerRunnable, 1000);
//
        if (playEngine.getPlayStatus() == PlayStatus.pause) {
            playEngine.resumePlay();
        }
//        int position = playEngine.getPlayer().getPosition() - onceSpeedLength;
//        playEngine.seekPlay(position);


    }
 /**
     * 分段播放呢时间索引
     */
    private ArrayList<SquareDanceModel> list;

 @Override
    public void parseJson(IJson json) {
        if (json.has("online")) {
            IJson onlineJson = json.getJson("online");
            if (onlineJson.has("url")) {
                try {
                    url = onlineJson.getString("url");
                    JSONArray urlarr = new JSONArray(url);
                    if (urlarr.length() > 0) {
                        url = (String) urlarr.get(0);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
                if (onlineJson.has("lastTime")){
                lastTime = onlineJson.getInt("lastTime");
            }
            if (onlineJson.has("size")){
                size = onlineJson.getInt("size");
            }
        }

后台下发数据,解析

 private int lastTime;
    //节点类型 1.前奏 2 正面 3 背面 4、慢节奏拍子 5.舞蹈小常识 6.广告  7 结尾
    private ArrayList<SquareDanceModel> list;
if (json.has("noteList")){
            IJson[] jsonArray = json.getJsonArray("noteList");
            if (jsonArray.length > 0) {
                list = new ArrayList<SquareDanceModel>();
                for (int i = 0; i< jsonArray.length; i ++) {
                    SquareDanceModel mode = new SquareDanceModel();
                    mode.parseJson(jsonArray[i]);
                    //节点类型 1.前奏 2 正面 3 背面 4、慢节奏拍子 5.舞蹈小常识 6.广告  7 结尾
                    if (!mode.isAd()){
                        list.add(mode);
                    }

                }
            }
        }
        if (list != null){
            doSquareDanceModel(list);
        }

        if (json.has("url")) { // 购买会员的url
            this.url = json.getString("url");
        }
    }


    /**
     * 排序
     * @param list
     */
    protected void doSquareDanceModel(ArrayList<SquareDanceModel> list) {
        Collections.sort(list, new Comparator<SquareDanceModel>() {
            @Override
            public int compare(SquareDanceModel model1, SquareDanceModel model2) {
                if (model1.getStart() < model2.getStart()) {
                    return -1;
                } else if (model1.getStart() > model2.getStart()) {
                    return 1;
                }
                return 0;
            }
        });
    }

监听当前点击

public interface SquareDanceMenuListener {

        void onPlayBtnClicked();

        void onNextBtnClicked();

        void onPrevBtnClicked();

        void onLoopSegmentBtnClicked();

        void onFavorateBtnClicked();
    }


@Override
    public void onClick(IUIViewBase arg0) {

        if (!Utils.isCanClick(getContext(), 500)) {
            return;
        }

        if (!NetworkUtils.isNetworkValidate(getContext())) {
            ToastUtils.showToast(getContext(), R.string.uitext_network_disconnection);
            return;
        }


        if (arg0 == preSegmentBtn) {// 上一段
            if (listener != null) {
                listener.onPrevBtnClicked();
            }
        } else if (arg0 == nextSegmentBtn) {
            if (listener != null) {
                listener.onNextBtnClicked();
            }
        } else if (arg0 == playPauseBtn) {
            if (listener != null) {
                listener.onPlayBtnClicked();
            }

        } else if (arg0 == loopSegmentBtn) {
            if (listener != null) {
                listener.onLoopSegmentBtnClicked();

            }
        } else if (arg0 == favorateBtn) {
            if (listener != null) {
                listener.onFavorateBtnClicked();

            }
        }

    }
可以使用开源的Java库如"JCodec"或"FFmpeg"来进行视频的TS处理。 其中,JCodec是一个Java视频解码器和编码器,它支持多种格式的视频和音频,包括TS格式。你可以使用JCodec来分离TS流并提取其中的视频和音频数据。 另外,FFmpeg是一个非常强大的开源跨平台视频处理工具,它也可以用于处理TS流。你可以使用Java中的"ProcessBuilder"类来执行FFmpeg的命令行工具。 以下是一个使用JCodec来进行TS处理的示例代码: ```java import org.jcodec.api.JCodecException; import org.jcodec.api.specific.ContainerAdaptor; import org.jcodec.api.specific.MP4Adaptor; import org.jcodec.common.io.NIOUtils; import org.jcodec.containers.mps.MPSDemuxer; import org.jcodec.containers.mps.MPSDemuxer.PESPacket; import org.jcodec.containers.mps.MTSUtils; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.file.Files; import java.nio.file.Paths; public class TSDemuxer { public static void main(String[] args) throws IOException, JCodecException { String filePath = "input.ts"; String videoOutPath = "output_video.ts"; String audioOutPath = "output_audio.ts"; // Create a demuxer for the input file ReadableByteChannel channel = NIOUtils.readableChannel(new File(filePath)); MPSDemuxer mpsDemuxer = new MPSDemuxer(channel); // Find the first video and audio streams int videoStreamIndex = -1; int audioStreamIndex = -1; for (int i = 0; i < mpsDemuxer.getNumStreams(); i++) { MPSDemuxer.StreamInfo info = mpsDemuxer.getStream(i); if (info.getCodec() != null && info.getCodec().startsWith("video/")) { videoStreamIndex = i; } else if (info.getCodec() != null && info.getCodec().startsWith("audio/")) { audioStreamIndex = i; } } // Create output files for video and audio Files.deleteIfExists(Paths.get(videoOutPath)); Files.deleteIfExists(Paths.get(audioOutPath)); Files.createFile(Paths.get(videoOutPath)); Files.createFile(Paths.get(audioOutPath)); // Create container adaptors for the output files ContainerAdaptor videoAdaptor = new MP4Adaptor(NIOUtils.writableChannel(new File(videoOutPath))); ContainerAdaptor audioAdaptor = new MP4Adaptor(NIOUtils.writableChannel(new File(audioOutPath))); // Process the input TS stream PESPacket pesPacket; while ((pesPacket = mpsDemuxer.nextFrame()) != null) { ByteBuffer data = pesPacket.getData(); int streamIndex = pesPacket.getStreamId(); // Write the video or audio data to the appropriate output file if (streamIndex == videoStreamIndex) { MTSUtils.writeSample(videoAdaptor, data, 0, pesPacket.getPts(), pesPacket.getDts(), true, null); } else if (streamIndex == audioStreamIndex) { MTSUtils.writeSample(audioAdaptor, data, 0, pesPacket.getPts(), pesPacket.getDts(), true, null); } } // Close the container adaptors videoAdaptor.finish(); audioAdaptor.finish(); } } ``` 这个示例代码使用JCodec来分离输入的TS流,并将其中的视频和音频数据写入到不同的输出文件中。你可以根据需要修改代码来适应你的具体需求。 除此之外,使用FFmpeg处理TS流的方式也类似,你可以调用FFmpeg的命令行工具来进行视频的分离和提取。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值