Parsing RSS Feed data to present a Podcast epsiodes list ,description and have a player to play podcast audio file in iOS device.
In here using AVPlayer to handle epsiode download from url and play the audio.
Separate the feature to three part
-
A list to present all epsiode.
-
A page with detail information of current epsiode.
-
A page with player to play epsiode.
-
List view
-
A header with podcast image
-
A List with epsiodes(contain: image, epsiode title, pubDate)
-
Refresh to reload RSS feed
-
Show description page
-
-
Description
-
A header with current epsiode image.
-
A section of text to display description of current epsiode.
-
Show player page
-
-
Player
-
A player to play/pause audio.
-
A slider to control progress.
-
Handle next epsiode when have newer epsiode.
-
Third part framework
-
Kinfisher for image download and cache.
-
XMLCoder for XML data parsing.
-
UIKit and programming UI layout.
-
Development env: XCode 13.1 RC
-
iOD Development Target: iOS 15
-
UIKit related:
UI Conponment
Key feature
UILayout
┌─────────────┐
│ RSSLoader │
└─────────────┘
▲
│
│
┌────────────────────────────┐ │
│ EpsiodeListFeatureComposer ├ ─ ─ │
└────────────────────────────┘ │ │
│ Creation │
│ │
│ ┌─────────────────────────────┐
└ ─ ─ ▶│ ListRefreshViewController │
│ └─────────────────────────────┘
┌──────────────▼──────────────┐ ▲
│ EpsiodeListViewController │─────────────────────────┘
└──────────────┬──────────────┘────┐
│ │
│ │
▼ │
┌─────────────────────────────┐ │
│ EpsiodeCellController │ │
└─────────────────────────────┘ │
│
│
│
│ ┌────────────────────┐
└────▶│ RSSFeedViewModel │
└────────────────────┘
-
EpsiodeListFeatureComposer
-
Create
ListRefreshViewController
withRSSLoader
-
Create
EpsiodeListViewController
withListRefreshViewController
-
Forwording refreshed rss data to
EpsiodeListViewController
-
-
EpsiodeListViewController
-
Receving
tableModel
as table view's data source -
As a table view controller to present epsiode list and header image.
-
Create
EpsiodeCellController
to present cell detail. -
hold
ListRefreshViewController
and connect to refresh control to show indicator when reloading. -
Navigate to
PodcastDescriptionViewController
with createdRSSFeedViewModel
.
-
┌─────────────┐
│PlayerObject │
└─────────────┘
▲
┌────────────────────┘
┌───────────────────────────────┴───┐
│ PodcastDescriptionViewController │
└───────────────────────────────┬───┘
└────────────────────────┐
▼
┌────────────────────┐
│ RSSFeedViewModel │
└────────────────────┘
-
PodcastDescriptionViewController
-
Create UI when receiving
RSSFeedViewModel
. -
Create
PlayerObject
and navigate toPodcastPlayerViewController
. -
Observe
PodcastPlayerViewController
on epsiode change event to change UI to current epsiode.
-
┌─────────────┐
│PlayerObject │
└─────────────┘
▲
┌────────────────────┘
┌───────────────────────────────┴───┐
│ PodcastPlayerViewController │
└───────────────────────────────┬───┘
└────────────────────────┐
▼
┌────────────────────┐
│ RSSFeedViewModel │
└────────────────────┘
-
PodcastPlayerViewController
-
Create UI when receiving
RSSFeedViewModel
and configPlayerObject
. -
Trigger prepareToPlay: Trigger
PlayerObject
to prepare player(download audio). -
Observe
PlayerObject
3 event and action.-
timeOnChange: To change current time label.
-
onPlayerReady: Trigger
onEpsiodeChange
to notifiedPodcastDescriptionViewController
to change UI for current epsiode. -
onEpEnd: Check if have newer epsiode.
- YES: config next epsiode to play.
- NO: stop epsiode and reset UI.
- YES: config next epsiode to play.
-
-
A object to handle AVPlayer
to play audio.
PlayerObject
register three observer to observe play state, and have three closure to notify controller what event happen.
-
observeValue: To observe is player is ready to play, using
onPlayerReady
to notify, and start to observe boundary time. -
addPeriodicTimeObserver: To observe time change and using
timeOnChange
to forwording current time string. -
addBoundaryTimeObserver: To observe is current epsiode is over, and using
onEpEnd
to notify controller.
-
prepareToPlay(with url): Prepare player, and using
observeValue
to observ status. -
handleSliderWith(with value): Receive slider value to control play time.
-
handlePlayPauseAndReturnIsPlaying: Check is avplayer playing.
-
resetPlayer: Reset avplayer to start condition.
-
getDuration: Get current epsiode duration and return time string.