URLSessionを使用してビデオをダウンロードし、appceleratorTitaniumで保存して再生する方法は?

ヘマントベーブル

URLSessionを使用してビデオをダウンロードして保存し、ビデオプレーヤーで再生しようとしています。しかし、どういうわけかそれは再生されていません、むしろそれはアプリをクラッシュさせています。ここではit.Iのコードは使用してファイルの正確なパスを読み取るために、ほとんどすべてのものを試してみましただnativePathgetNativePath()file.resolve()、何も動いていないようにみえ。コードを見て、解決策を提案してください。これはiOS用です。(iOSバージョン8.4)

更新されたコード:

    var args = arguments[0] || {};

    var vidWin = $.winTestVideo;
    var isDownloading = false;

    var urlSession = require("com.appcelerator.urlSession");
    var downloadSession;

    var urlArray = ["http://www.kaltura.com/p/{PARTNERID}/sp/{SUBPARTNERID}/playManifest/entryId/{entryId}/format/applhttp/protocol/http/flavorId/{flavorId}/video.mp4",
"http://www.kaltura.com/p/{PARTNERID}/sp/{SUBPARTNERID}/playManifest/entryId/{entryId}/format/applhttp/protocol/http/flavorId/{flavorId}/video.mp4"];

    var urlArrIndex = 0;
    var progress;
    var videoPlayer;
    var imageUrl = 'http://dreamatico.com/data_images/rose/rose-4.jpg';
    //'http://cdn.playbuzz.com/cdn/5d41f0c6-2688-47fe-85cf-82890ef6d91d/45611be8-42f9-4d02-9b63-f7195c0dc18c_560_420.jpg';
    var img;
    function onLoad() {
        Alloy.Globals.CurrentWindowName = 'testvideoplayer';
        var triggerBtn = Ti.UI.createButton({
            top : 10,
            width : Ti.UI.FILL,
            height : 40,
            backgroundColor : "#cccccc",
            color : "#000000",
            title : "Download Videos"
        });
        vidWin.add(triggerBtn);
        triggerBtn.addEventListener('click', downloadVideoBackround2);

        progress = Titanium.UI.createProgressBar({
            width : 200,
            height : 20,
            min : 0,
            max : 1,
            value : 0,
            top : 60,
            backgroundColor : "#0000ff",
            style : Ti.UI.iPhone.ProgressBarStyle.BAR,

        });

        vidWin.add(progress);

        img = Ti.UI.createImageView({
            width : 100,
            height : 100,
            backgroundColor : "#cccccc"
        });
        //vidWin.add(img);

        //videoPlayer.play();

    }

    function createVideoPlayer() {
        videoPlayer = Ti.Media.createVideoPlayer({
            width : Ti.UI.FILL,
            height : 240,
            top : 100,
            mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
            scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
            backgroundColor : "#000000",

        });
        vidWin.add(videoPlayer);
        videoPlayer.removeEventListener('playbackstate', playbackStateEventListener);
        videoPlayer.addEventListener('playbackstate', playbackStateEventListener);
    }

    // Require in the urlSession module
    var urlSession = require("com.appcelerator.urlSession");
    var session;
    // App UI

    function playbackStateEventListener(evt) {
        Ti.API.error("PlaybackStateEventListener  : " + JSON.stringify(evt));
    }

    function downloadVideoBackround2(evt){
        // Create a session configuration
        // The string parameter is an arbitrary string used to identify the session in events
        var sessionConfig = urlSession.createURLSessionBackgroundConfiguration("com.appcelerator.test");
        // Create a session
        session = urlSession.createURLSession(sessionConfig);
        // Create a background download task to get the asset with the URL
        urlSession.backgroundDownloadTaskWithURL(session,urlArray[0].replace('applhttp','url'));
        progress.show();
    }

    // Monitor this event to receive updates on the progress of the download
    Ti.App.iOS.addEventListener("downloadprogress", function(e) {
        // Update the progress indicator
        Ti.API.error("DOWNLOAD PROGRESS : " + e.totalBytesWritten + "/" + e.totalBytesExpectedToWrite);
        progress.value = (e.totalBytesWritten / e.totalBytesExpectedToWrite);
    });

    // Monitor this event to know when the download completes
    Ti.App.iOS.addEventListener("downloadcompleted", function(e) {
        Ti.API.error("download completed " + JSON.stringify(e));
        // Update the image
        try {

            var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'myplvideo.mp4');
            if (!file.exists()) {
                file.createFile();
            }
            file.write(e.data);
            Ti.API.error('data : ' + e.data.length);
            Ti.API.error('file : ' + file.nativePath);
            Ti.API.error('file resolve path :' + file.resolve());
            progress.hide();

            // Notify the user the download is complete if the application is in the background
            setTimeout(function() {

                //videoPlayer.media = file;
                createVideoPlayer();
                videoPlayer.media = file;
                urlSession.finishTasksAndInvalidate(session);
                //videoPlayer.play();
            }, 3000);

            //alert('Download completed!');
            /*
             Ti.App.iOS.scheduleLocalNotification({
             alertAction : "update",
             // Alert will display the following message
             alertBody : "Download was successfull",
             // The badge value in the icon will be changed to 1
             badge : 1,
             // Alert will be sent in three seconds
             date : new Date(new Date().getTime() + 3000),
             });*/

        } catch(ex) {
            Ti.API.error('download completed : ' + ex);
        }
    });
    // Monitor this event to know when all session tasks have completed
    Ti.App.iOS.addEventListener('sessioncompleted', function(e) {
        try {

            Ti.API.error("sessioncompleted " + JSON.stringify(e));
            if (e.success) {
                //alert("Downloads completed successfully.");
            }
        } catch(ex) {
            Ti.API.error('Exception session completed : ' + ex);
        }
    });

プロパティfile割り当てると、アプリがクラッシュします。しかし、HttpClientを使用してファイルをダウンロードすると、正常に動作します。ログにエラーが表示されないため、なぜ発生しているのかよくわかりません。videoPlayermedia

これがログです。重要なログを強調するために[エラー]を使用しました。

[ERROR] :  DOWNLOAD PROGRESS : 67470/5794757
[ERROR] :  DOWNLOAD PROGRESS : 133006/5794757
[ERROR] :  DOWNLOAD PROGRESS : 199614/5794757
[ERROR] :  DOWNLOAD PROGRESS : 266222/5794757
[ERROR] :  DOWNLOAD PROGRESS : 275982/5794757
[ERROR] :  DOWNLOAD PROGRESS : 341518/5794757
[ERROR] :  DOWNLOAD PROGRESS : 408126/5794757
[ERROR] :  DOWNLOAD PROGRESS : 474734/5794757
[ERROR] :  DOWNLOAD PROGRESS : 541342/5794757
[ERROR] :  DOWNLOAD PROGRESS : 609398/5794757
[ERROR] :  DOWNLOAD PROGRESS : 677454/5794757
[ERROR] :  DOWNLOAD PROGRESS : 745510/5794757
[ERROR] :  DOWNLOAD PROGRESS : 758166/5794757
[ERROR] :  DOWNLOAD PROGRESS : 823702/5794757
[ERROR] :  DOWNLOAD PROGRESS : 897550/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1048142/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1114750/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1182806/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1249414/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1316022/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1382630/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1385150/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1450686/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1518742/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1586798/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1653406/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1720014/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1786622/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1854678/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1921286/5794757
[ERROR] :  DOWNLOAD PROGRESS : 1989342/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2057398/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2059918/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2125454/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2205094/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2271702/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2341206/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2342278/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2407814/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2410334/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2475870/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2542478/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2609086/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2675694/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2676766/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2742302/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2808910/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2876966/5794757
[ERROR] :  DOWNLOAD PROGRESS : 2943574/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3010182/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3076790/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3143398/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3212902/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3274790/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3340326/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3422862/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3557526/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3624134/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3692190/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3758798/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3825406/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3893462/5794757
[ERROR] :  DOWNLOAD PROGRESS : 3960070/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4026678/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4094734/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4161342/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4227950/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4294558/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4362614/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4430670/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4497278/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4498350/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4563886/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4630494/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4697102/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4699622/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4765158/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4831766/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4898374/5794757
[ERROR] :  DOWNLOAD PROGRESS : 4964982/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5031590/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5098198/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5106510/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5172046/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5319742/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5320814/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5386350/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5455854/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5523910/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5591966/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5658574/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5726630/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5794686/5794757
[ERROR] :  DOWNLOAD PROGRESS : 5794757/5794757
[ERROR] :  download completed {"taskIdentifier":1,"data":{},"bubbles":true,"type":"downloadcompleted","source":{},"cancelBubble":false}
[ERROR] :  open on /var/mobile/Containers/Data/Application/9FBAAEB4-4878-4611-8BCC-EFC112AF9777/Documents/myplvideo.mp4: File exists
[ERROR] :  data : 5794757
[ERROR] :  file : file:///var/mobile/Containers/Data/Application/9FBAAEB4-4878-4611-8BCC-EFC112AF9777/Documents/myplvideo.mp4
[ERROR] :  file resolve path :/var/mobile/Containers/Data/Application/9FBAAEB4-4878-4611-8BCC-EFC112AF9777/Documents/myplvideo.mp4
[ERROR] :  sessioncompleted {"success":true,"message":"","errorCode":0,"taskIdentifier":1,"bubbles":true,"type":"sessioncompleted","source":{},"cancelBubble":false}
スティーブンフェザー

私の簡単な推測では、あなたは競合状態にあると思います。setTimeout内では、ダウンロードが終了したときのように、ファイルが書き込まれたかどうかを実際に確認することはありません。この時点で3秒で十分であると想定しています。

// Notify the user the download is complete if the application is in the background
setTimeout(function() {
  //videoPlayer.media = file;
  createVideoPlayer();
  videoPlayer.media = file;
  urlSession.finishTasksAndInvalidate(session);
  //videoPlayer.play();
}, 3000);

さらに、デバイスまたはシミュレーターのxcodeログは、クラッシュした場所/内容を示している必要があります(これらはチタンログに常に表示されるとは限りません)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Android:LANを使用してダウンロードしながらmp4ビデオファイルを再生することは可能ですか?

分類Dev

pygameでビデオをロードして再生する方法

分類Dev

JSを使用してビデオタグをダウンロードする方法は?

分類Dev

nodejsを使用してcloudinaryからビデオをダウンロードする方法は?

分類Dev

opencvを使用してGooglecolabでビデオを再生する方法は?

分類Dev

iOSでOpenGLを使用してビデオを再生する方法は?

分類Dev

Realmを使用してiOSアプリ(Swift 3.0)でストリーミングビデオをダウンロードして保存する

分類Dev

ttdownloaderからPythonを使用してビデオをダウンロードする

分類Dev

Retrofitを使用してURLからビデオをダウンロードする

分類Dev

requestbodyでurlsessionを使用してファイルをダウンロードする方法

分類Dev

コマンドラインでVLCを使用してYouTubeからビデオをダウンロードする

分類Dev

ダウンロードした.mp4ビデオをAndroidのvideoviewで再生する方法

分類Dev

Androidで画像をダウンロードして保存する方法

分類Dev

Androidで.movformateを使用してURIを使用してオンラインビデオを再生する方法は?

分類Dev

ドキュメントディレクトリにビデオを保存またはダウンロードして、ドキュメントディレクトリから再生することができません

分類Dev

SDWebImageを使用してCGImageをダウンロードして保存する方法

分類Dev

テレソンを使用してビデオをダウンロードする方法

分類Dev

オーディオをダウンロードしてAVAudioPlayerで再生

分類Dev

VB.netを使用してYouTubeビデオをダウンロードする方法

分類Dev

youtube-dlを使用して1080p +最高のオーディオをダウンロードする方法は?

分類Dev

Androidでオーディオをダウンロードしてストリーミングする方法は?

分類Dev

pytubeを使用してmp3形式でビデオをダウンロードする

分類Dev

Androidでインテントを使用してストリームビデオを再生する方法は?

分類Dev

openCVpythonを使用して再生中にビデオウィンドウを移動する方法

分類Dev

youtube-dlを使用して、ビデオを一括ダウンロードし、同時に名前を変更する方法は?

分類Dev

SwiftでAVPlayerViewController(AVKit)を使用してビデオを再生する方法

分類Dev

なぜwgetは含まれているビデオをダウンロードしないのですか?

分類Dev

asyncを使用してNodeJSでシリーズのビデオを次々にダウンロードしますか?

分類Dev

ビデオを再生して字幕を自動的にロードする方法

Related 関連記事

  1. 1

    Android:LANを使用してダウンロードしながらmp4ビデオファイルを再生することは可能ですか?

  2. 2

    pygameでビデオをロードして再生する方法

  3. 3

    JSを使用してビデオタグをダウンロードする方法は?

  4. 4

    nodejsを使用してcloudinaryからビデオをダウンロードする方法は?

  5. 5

    opencvを使用してGooglecolabでビデオを再生する方法は?

  6. 6

    iOSでOpenGLを使用してビデオを再生する方法は?

  7. 7

    Realmを使用してiOSアプリ(Swift 3.0)でストリーミングビデオをダウンロードして保存する

  8. 8

    ttdownloaderからPythonを使用してビデオをダウンロードする

  9. 9

    Retrofitを使用してURLからビデオをダウンロードする

  10. 10

    requestbodyでurlsessionを使用してファイルをダウンロードする方法

  11. 11

    コマンドラインでVLCを使用してYouTubeからビデオをダウンロードする

  12. 12

    ダウンロードした.mp4ビデオをAndroidのvideoviewで再生する方法

  13. 13

    Androidで画像をダウンロードして保存する方法

  14. 14

    Androidで.movformateを使用してURIを使用してオンラインビデオを再生する方法は?

  15. 15

    ドキュメントディレクトリにビデオを保存またはダウンロードして、ドキュメントディレクトリから再生することができません

  16. 16

    SDWebImageを使用してCGImageをダウンロードして保存する方法

  17. 17

    テレソンを使用してビデオをダウンロードする方法

  18. 18

    オーディオをダウンロードしてAVAudioPlayerで再生

  19. 19

    VB.netを使用してYouTubeビデオをダウンロードする方法

  20. 20

    youtube-dlを使用して1080p +最高のオーディオをダウンロードする方法は?

  21. 21

    Androidでオーディオをダウンロードしてストリーミングする方法は?

  22. 22

    pytubeを使用してmp3形式でビデオをダウンロードする

  23. 23

    Androidでインテントを使用してストリームビデオを再生する方法は?

  24. 24

    openCVpythonを使用して再生中にビデオウィンドウを移動する方法

  25. 25

    youtube-dlを使用して、ビデオを一括ダウンロードし、同時に名前を変更する方法は?

  26. 26

    SwiftでAVPlayerViewController(AVKit)を使用してビデオを再生する方法

  27. 27

    なぜwgetは含まれているビデオをダウンロードしないのですか?

  28. 28

    asyncを使用してNodeJSでシリーズのビデオを次々にダウンロードしますか?

  29. 29

    ビデオを再生して字幕を自動的にロードする方法

ホットタグ

アーカイブ