simonwell
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # P2P接入文檔說明文件 V0.1 ## :books:iOS SDK 概述 [![P2P_SDK](https://i.imgur.com/5gaXOsz.jpg "P2P_SDK")](https://i.imgur.com/5gaXOsz.jpg "P2P_SDK") :::info 從上圖可以了解,P2P SDK包括2個部分,本地HTTP Server,與P2P接口。綠色部分是播放器通過本地HTTP Server請求本地視頻資源,紅色部分是P2P點對點接口進行資源下載與上傳(需 透過資源服務器發布的資源網址),由P2P下載視頻資源至本地存儲空間。再由播放器向HTTP Server請求的視頻資源,達到資源下載的同時可即時播放視頻。 ::: ## :closed_book:iOS SDK 集成指南 ### SDK 說明 #### 資源文件 包名為 libs-{==版本号==}-sdk-ios-full.zip 例如:libs-v.1.8.18.26-sdk-ios-full.zip 解壓縮後產生libp2p.framework,包含以下目錄或檔案: 1. `_CodeSignature 目錄:mac自動產生的文件` 2. `Headers 目錄:主要頭文件` 3. `Info.plist:plist檔案` 4. `libptp:主要封裝的library` #### 創建應用 > 輸入相關AppKey才可以進行試用 ==doxstarthttpd(key輸入trial的APP_KEY值)== ### 配置工程 #### 導入SDK方式:`手動導入` > 請到 WithVideo SDK 網站下載[最新的SDK](http://sdk.xtsdy.com/download.html?LANG=zh-tw "最新的SDK") - 添加Framework,拉到以下位置 [![添加libp2p.framework](https://i.imgur.com/kSyOt2i.png)](https://imgur.com/kSyOt2i.png) #### 啟動p2p服務 在以下function添加此code ```objective-c - (BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions { NSString *dir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; NSString *keyStr = @"APP KEY"; const char *key = [keyStr UTF8String]; const char *szdir = [dir UTF8String]; int http_port = doxstarthttpd((char*)key,(char*)szdir ); doxsetloglevel(0); } ``` #### 下載P2P檔案 ```objective-c NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000); const char *url = [url cStringUsingEncoding:gbkEncoding]; doxadd(url); dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{ int videoId = doxdownload(url); }); ``` #### 播放P2P視頻 ```objective-c NSString *urlString = @"ftp://xxxx/xxxxx/xxxxx.mp4"; dispatch_group_t group = dispatch_group_create(); dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^{ int p2pVid = [p2papi doxstart:urlString]; }); NSString *vod_name = [urlString lastPathComponent]; NSString *localfile = [[[NSMutableString alloc]initWithFormat:@"http://127.0.0.1:%d/",[p2papi getport]] stringByAppendingString:vod_name]; NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000); NSURL *url = [NSURL URLWithString:[localfile stringByAddingPercentEscapesUsingEncoding:gbkEncoding]]; ijkplayr.assetURL = url; ``` ## :mag:iOS SDK 接口說明 ==int doxstarthttpd(const char * key, const char* content);== `SDK初始化調用需先啟動HTTP Server才能進行播放下載` **參數說明** * key : API KEY值 * content : 資料夾路徑 * int : 本地 http port --- ==int doxadd(const char * url);== `下載或播放前視頻都必須加到SDK下載對列,調用此方法才能進行P2P資源分享` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列ID --- ==int doxdownload(const char * url);== `下載資源不播放調用此方法,主要在下載列表或清單此方法(需異步調用)` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列ID --- ==int doxstart(const char * url);== `播放視頻前調用此方法播放器才能對本地HTTP請求視頻播放,此方法同時會進行資源下載(需異步調用)` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列ID --- ==int doxdel(const char * url);== `刪除特定視頻的本地緩存如手機空間不足可調用` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列ID --- ==int doxdelall(void);== `清除所有下載的視頻緩存` --- ==getspeed(int t);== `獲取視頻下載速度` **參數說明** * t : 視頻的隊列 ID --- ==int doxsave();== `保存視頻的進度與狀態 在離開App時調用` **參數說明** * int : 視頻的隊列 ID --- ==void dosetupload(int limit);== `設置P2P最大上傳速度 需在初始化時調用` **參數說明** * int : 最大上傳速度 --- ==int doxpause(const char * url);== `暫停視頻的下載` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列 ID --- ==int doxcheck(const char * url);== `檢查視頻是否已完全下載至本地` **參數說明** * url : 視頻的原始網址 * int : 視頻的隊列 ID --- ==std :: string doxgettaskstat(int tt);== `獲取視頻下載P2P狀態` **參數說明** * tt : 視頻的隊列 ID * std : 視頻下載狀態字串(下載速度 種子數 檔案大小 已下載大小) --- ==void doxsetloglevel(int level);== `Log Info 顯示等級` **參數說明** * level : 0~7 --- ==getdownsize(int t);== `獲取視頻已下載大小(需異步調用)` **參數說明** * t : 視頻的隊列 ID --- ==getfilesize(int t)== `獲取視頻檔案大小` **參數說明** * t : 視頻的隊列 ID --- ==int getpercent(int t);== `獲取視頻已下載百分比(需異步調用)` **參數說明** * t : 視頻的隊列 ID --- ==getlocalfilesize(const char * url);== `獲取已下載完成視頻檔案大小` **參數說明** * url : 視頻的原始網址 --- **以下暫時不使用** > int doxterminate(); > > int doxsetduration(int dur); > > int doxShare(const char * url,float lng,float lat); > > const char * doxGetShare(float lng,float lat); > > int endhttpd(); ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully